Skip to content

Add gatsby-plugin-typegen instead of codegen#266

Merged
orta merged 3 commits intomicrosoft:v2from
item4:gatsby-plugin-typegen
Feb 19, 2020
Merged

Add gatsby-plugin-typegen instead of codegen#266
orta merged 3 commits intomicrosoft:v2from
item4:gatsby-plugin-typegen

Conversation

@item4
Copy link
Contributor

@item4 item4 commented Feb 19, 2020

I think website of TypeScript must be type-safe, right?
But, there is few type definition only.
Almost props of components use (props: any). 😱
So... I make type definition file automatically with gatsby-plugin-typegen.
This plugin support autogenerated type-def file with gatsby together.

Please read this PR and consider merge.

1. Remove codegen plugin and its generated codes.
2. Apply typegen plugin and add type of props for much components.
@item4 item4 requested a review from orta February 19, 2020 09:40
@msftclas
Copy link

msftclas commented Feb 19, 2020

CLA assistant check
All CLA requirements met.

@orta
Copy link
Contributor

orta commented Feb 19, 2020

Ha nice, I only removed it a day or two ago because I introduced the shared fragments and the old one couldn't handle it!

If you can add the generated types to gitignore then this is good to go thanks! Wooo

@orta
Copy link
Contributor

orta commented Feb 19, 2020

GitHub is having issues, I'm gonna manually merge this! Thanks!

@orta orta merged commit 49d54b1 into microsoft:v2 Feb 19, 2020
@cometkim
Copy link

Hey @item4 and @orta, I'm author of the plugin. I'm really happy to see that the official TypeScript webpage uses my plugins, appreciates all of your work.

The plugin is currently actively developing. so If you have any trouble to use the plugin, please give feedback.

@item4 item4 deleted the gatsby-plugin-typegen branch February 19, 2020 23:59
}[]
}
import { SitePage } from "../__generated__/gatsby-types";
export type AllSitePage = { readonly nodes: ReadonlyArray<Pick<SitePage, 'path'>> };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just changed this to:

import { AllSitePageFragment } from "../__generated__/gatsby-types";
export type AllSitePage = AllSitePageFragment["allSitePage"];

in case you don't know about the type accessor feature in TS

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh. It's nice. thanks your kindness :)

@orta
Copy link
Contributor

orta commented Feb 20, 2020

👍 it's working so far

@Urigo
Copy link

Urigo commented Feb 24, 2020

that's awesome!
We also use that plugin (we are a bit biased as it's using https://github.com/dotansimha/graphql-code-generator under the hood ;) )

@orta if you think this is good, I think it would be a good idea to update your amazing blog post on Gatsby and Typescript.
I assume a lot of people will read it and use it as a resource!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants