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

Passing an unknown field does not report type errors #68

Open
1 task
mizdra opened this issue Mar 10, 2024 · 1 comment
Open
1 task

Passing an unknown field does not report type errors #68

mizdra opened this issue Mar 10, 2024 · 1 comment
Labels
Type: Fix Fix bug.

Comments

@mizdra
Copy link
Owner

mizdra commented Mar 10, 2024

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

@mizdra mizdra added the Type: Fix Fix bug. label Mar 10, 2024
@mizdra
Copy link
Owner Author

mizdra commented Mar 16, 2024

It may be a good idea to provide a lint rule. https://github.com/johnsoncodehk/typescript-linter would be useful for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Fix Fix bug.
Projects
None yet
Development

No branches or pull requests

1 participant