Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: TS type error on `strictNullChecks: true (#7931)
`Partial<T>` includes `{}`, therefore `NewVisitor[keyof NewVisitor]` includes `undefined`, and indexing `undefined` is error. Issue: #7519
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
'@graphql-codegen/plugin-helpers': patch | ||
--- | ||
|
||
Fix TS type error on strictNullChecks: true | ||
|
||
Fix the compiler error: | ||
|
||
``` | ||
node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:5:75 - error TS2339: Property 'enter' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'. | ||
5 enter?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['enter']>>; | ||
~~~~~~~ | ||
node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:6:75 - error TS2339: Property 'leave' does not exist on type '{ readonly enter?: ASTVisitFn<NameNode> | undefined; readonly leave: ASTReducerFn<NameNode, unknown>; } | { readonly enter?: ASTVisitFn<DocumentNode> | undefined; readonly leave: ASTReducerFn<...>; } | ... 41 more ... | undefined'. | ||
6 leave?: Partial<Record<keyof NewVisitor, NewVisitor[keyof NewVisitor]['leave']>>; | ||
~~~~~~~ | ||
Found 2 errors in the same file, starting at: node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts:5 | ||
``` | ||
|
||
Only happens when TS compiler options `strictNullChecks: true` and `skipLibCheck: false`. | ||
|
||
`Partial<T>` includes `{}`, therefore `NewVisitor[keyof NewVisitor]` includes `undefined`, and indexing `undefined` is error. | ||
Eliminate `undefined` by wrapping it inside `NonNullable<...>`. | ||
|
||
Related #7519 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a4fe500
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
graphql-code-generator – ./
graphql-code-generator.vercel.app
graphql-code-generator-git-master-theguild.vercel.app
graphql-code-generator-theguild.vercel.app
www.graphql-codegen.com
graphql-code-generator.com
www.graphql-code-generator.com
graphql-codegen.com