-
Notifications
You must be signed in to change notification settings - Fork 23
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
Feature: Suport d.ts output (global declarations) #24
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:
|
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 |
If the declaration scope is global, some declaration like 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. |
Changed generated types to the global declaration as default, so it can be used without manual imports. And use a namespace(default is `GatsbyTypes`) to avoid type conflicts with other global declarations. It doesn't allow undefined or empty string, after the upgrade, every typenames in user codebase will be changed by the namespace. ```tsx import type { SEOQuery } from '~/src/__generated__/gatsby-types'; function SEO() { const data = useStaticQuery<SEOQuery>( graphql` query SEO { ... } ` ); ... ``` will be changed into: ```tsx // no need to import the type function SEO() { const data = useStaticQuery<GatsbyTypes.SEOQuery>( graphql` query SEO { ... } ` ); ... ``` Since the Flow doesn't have namespace syntax, It uses `$` as the fallback behavior. Closes #24 Closes #16
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. |
No description provided.
The text was updated successfully, but these errors were encountered: