Skip to content

More type-safe projection type #683

@ejmartin504

Description

@ejmartin504

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions