cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety

Home Page:https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

  1. Use the noExport: true option.
  2. Find all type|interface definitions and prepand the declare keyword.
  3. 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.