Feature: Suport d.ts output (global declarations)
cometkim opened this issue · comments
Not having to manually import the types would be amazing. Would make this plugin a no brainer for every Gatsby dev.
It seems to not able to be done with only codegen configurations. (Or I couldn't figure out how)
The simplest way I found is:
- Use the
noExport: true
option. - Find all type|interface definitions and prepand the
declare
keyword. - Make file extension to '.d.ts' instead of '.ts'
Obviously, Flow can also use a global declaration, so this new option should be treated as a mixed config, not a new language.
The codegen's Flow plugins don't support noExport
option yet. I can preferentially release the TypeScript support during waiting for it or contributing directly.
If the declaration scope is global, some declaration like File
is conflicted.
In order to use a declaration, it must specify namespace scope or using the global namespace with a prefix to avoid conflicts.
flow has no namespace syntax, so it must use prefixes.
Hey @fandy, I just published v2.0.0 that uses global declaration by default. Please try to migrate, and feedback will be appreciated.
Generation like a charm! Would be great if it could automatically sync the types to page queries, but I understand that'd be harder to implement.
Additional feedback: would be super useful to be able to import the field types, meaning not just the query, but the types for the fields in those queries.