mizdra / graphql-codegen-typescript-fabbrica

GraphQL Code Generator Plugin to define fake data factory.
MIT License
29 stars 1 forks source link

TS error when exporting #85

Closed bmulholland closed 16 hours ago

bmulholland commented 1 week ago

Environment

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

Summary

I'm starting adoption of this library (which is awesome -- thank you!!) and am trying to extract my first factory to a file I can import in different places.

When I do, Typescript complains: The inferred type of 'default' cannot be named without a reference to '~/node_modules/@mizdra/graphql-codegen-typescript-fabbrica/dist/esm/helper/factory'. This is likely not portable. A type annotation is necessary. ts (2742)

If I instead name the import myself, then I get another complaint: The inferred type of 'XFactory' cannot be named without a reference to '~/node_modules/@mizdra/graphql-codegen-typescript-fabbrica/dist/esm/helper/factory'. This is likely not portable. A type annotation is necessary. ts (2742)

I tried to add a manual type annotation, but that requires quite some contortions, and still seems to cause errors...

Is there something I'm missing? Is there a recommended way to deal with the typing here?

Step to reproduce

above

What did you expect to happen?

above

What actually happened?

above

Participation

Additional comments

No response

mizdra commented 1 week ago

Thank you for sending bug report!

I could not figure out what code to write to reproduce it. Could you please provide the code to reproduce it?

TIPS: You can easily create reproducible code by forking the playground.

bmulholland commented 1 week ago

Sure, here you go: https://stackblitz.com/edit/playground-graphql-codegen-typescript-fabbrica-xqluvt?file=src%2Fbookfactory.ts

The key is adding composite: true to the TS config.

mizdra commented 1 week ago

Thanks. I was able to reproduce the problem. I will try to resolve this issue.

mizdra commented 1 week ago

The editor and Language Server (tsserver) report compile errors, but npx tsc does not seem to report compile errors. This is very strange...

image
$ npx tsc
$ echo $?
0
mizdra commented 1 week ago

When --noEmit is true, it seems that the compile error is not outputted. When --noEmit is false, the behavior is as expected.

https://stackblitz.com/edit/playground-graphql-codegen-typescript-fabbrica-8gryg6?file=tsconfig.json,package.json,src%2Fbookfactory.ts