Skip to content

Passing an unknown field does not report type errors #68

@mizdra

Description

@mizdra

Environment

@mizdra/graphql-codegen-typescript-fabbrica version: 0.3.2
typescript version (optional):
@graphql-codegen/cli version (optional):
@graphql-codegen/typescript version (optional):

Summary

I would expect a type error to be reported when an unknown field is passed to defaultFields, but it is not.

type Book {
  title: String!
}
import { defineBookFactory } from '../__generated__/fabbrica';

const BookFactory = defineBookFactory({
  defaultFields: {
    title: 'Yuyushiki',
    // @ts-expect-error I expect a type error to be reported, but it is not.
    unknownField: 'hello',
  },
});

Step to reproduce

https://stackblitz.com/edit/playground-graphql-codegen-typescript-fabbrica-4yjhkc?file=src%2Findex.test.ts&view=editor

What did you expect to happen?

A type error is reported.

What actually happened?

No type errors are reported.

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

It may be necessary to assign a dedicated type parameter for each field.

https://www.typescriptlang.org/play?#code/C4TwDgpgBA8mwEsD2A7AhgGwEJKQaygF4oBvAKCikWAwgH4AuKAZ2ACcEUBzKAHygCuKACYQAZpwjCA3BSgJhjFu049+Q0RJRTZAX1llRAYwxo20MUKOJUUAEYCEGYTnwBGADwAVKBAAewBAizLDwyOjYuHgAfAAUZlzMTF4AlMmyRqisUObMAhjAbkT2js6ueG6x5AD01ZSUAHp0ctS0TADkaO0ANHK1UAACwMwAtP6Q1mNsbEhsckJ4KEgA7igAYggQzkxuvbopsrG5+YUsaIjMEhAhJFQINBBMrBzcUPsGxqbmUJYo1uElJwuKIAJm8vgCQWEITgNgi5QA2u1WhB2gBdYoacSSYTdKAAVQhgWCoThmER7QU6MxImx2mEcQSSVIdweSi8eIUSkJ+yYtxRyU5wiYPIyWWAOWuJxBxQcQPKIKqZH69SaLXubSgnR6fTqQ1G4wgkwg01m8xQixW6022yguzI7zIRylBRlzHOCEumxurM1z1UbwOZEMRq+FiscMBZSiAGZwf5idDSeFyVFGWxEnzfY8oF4kSj0ULkkiqRjebmxShsscCjHZaVgfgY0qVY1mpQBVqur1KP19WM-BNgFMZnNKAslqsNlthXa9kHnXla2cLlcfZ3-a9HUA

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions