Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More type-safe projection type #683

Open
ejmartin504 opened this issue Dec 15, 2023 · 1 comment
Open

More type-safe projection type #683

ejmartin504 opened this issue Dec 15, 2023 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ejmartin504
Copy link
Collaborator

Consider the following schema:

const mySchema = schema(
  {
    foo: Types.string(),
    bar: Types.string()
});

const MyModel = papr.model('mymodels', mySchema);

Now consider some code that queries this model:

const t = MyModel.find(
  { foo: 'baz' },
  {
    projection: {
      foo: 1,
      unknown: 1
    }
  }
);

Currently this projection type will not produce a TS error even though it is projecting properties that do not exist on the schema. This can be problematic in applications, especially because it will not flag misspelled properties (an issue we ran into recently)

@avaly avaly added enhancement New feature or request help wanted Extra attention is needed labels Jan 9, 2024
@joshuat
Copy link
Collaborator

joshuat commented Jan 19, 2024

I bet this is being caused by the combination of using a Partial on the projection type definition and having the projection type defined in the generic so we can use it in the return value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants