Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

[codegen] improve importing types from generated file #86

Open
d4rekanguok opened this issue Apr 14, 2020 · 7 comments
Open

[codegen] improve importing types from generated file #86

d4rekanguok opened this issue Apr 14, 2020 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@d4rekanguok
Copy link
Owner

This way user can just import the file directly

import { MyQuery } from 'gatsby-ts'

Instead of the ../../.. they're doing now.

Also avoid the confusion shown in #85

@cometkim
Copy link

FYI: This will never work with Yarn 2

@cometkim
Copy link

And when my plugin had used this approach by default before, TypeScript did detect changes in node_modules rather slower than in src. (in VSCode, not sure it's IDE dependent)

@d4rekanguok
Copy link
Owner Author

ha, forgot about that.. thanks for the reminder! @cometkim

@ricokahler
Copy link
Collaborator

@d4rekanguok I haven't confirmed if this will work or not but here's an idea:

  1. Instead of writing to node_modules we can write to gatsby .cache.
  2. We can utilize the tsconfig.extends option and advise users to extend a pre-made configuration that will include this cache location

As far as I know, i think it's possible to create a packages for tsconfigs.


So I think users would have tsconfig files that would look like this:

{
  "extends": "gatsby-ts/tsconfig",
  "compilerOptions": {
    // ...
  },
  // ...
}

And our base config would include a typeRoots configuration that will look in the .cache folder.

@d4rekanguok
Copy link
Owner Author

@ricokahler That's a nice idea, I'll give it a try locally!

@d4rekanguok d4rekanguok changed the title [codegen] Build file straight to node_modules [codegen] improve importing types from generated file May 7, 2020
@d4rekanguok d4rekanguok added the enhancement New feature or request label May 7, 2020
@cometkim
Copy link

cometkim commented May 7, 2020

@d4rekanguok you should checkout the typegen plugin. Since v2, I've moved generated type definitions into a specific namespace declaration, TypeScript will understand the definition without importing module.

NexusJS also has a similar approach with this and they have great DX with code generation.

@d4rekanguok
Copy link
Owner Author

Thanks @cometkim, I'll check it out v2 & also nexusJS!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants