cometkim / gatsby-plugin-typegen

Let's give developers using GatsbyJS better DX with extreme type-safety
https://www.gatsbyjs.org/packages/gatsby-plugin-typegen/
MIT License
204 stars 25 forks source link

why noExport default options set true..? #170

Closed youngrove closed 2 years ago

youngrove commented 2 years ago

Issue

My auto generated types is here..

// no export 
declare namespace GatsbyTypes {
...

But, I can't use GatsbyTypes for My query.

Screen Shot 2022-01-30 at 7 24 16 PM

In codegen.ts

const DEFAULT_TYPESCRIPT_CONFIG: Readonly<TypeScriptPluginConfig> = {
  avoidOptionals: true,
  immutableTypes: true,
  maybeValue: 'T | undefined',
  noExport: true,
  enumsAsTypes: true,
};
youngrove commented 2 years ago

I added this line when I used generated types...

/// <reference path = "../__generated__/gatsby-types.ts" />

And I Got this error. I Knew If I change ts.config file It will resolved.. But I wonder why set default noexport options set true..

'gatsby-types.ts' cannot be compiled under '--isolatedModules' because it is considered a global script file. Add an import, export, or an empty 'export {}' statement to make it a module.

cometkim commented 2 years ago

As you can see, the codegen output doesn't use any module output, but just declare the global namespace GatsbyTypes.

This may be incompatible with the --isolatedModules, so you can explicitly mark it as *.d.ts if needed.