Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TS type error on strictNullChecks: true #7931

Merged
merged 1 commit into from
Jul 8, 2022

Conversation

dittos
Copy link
Contributor

@dittos dittos commented Jun 11, 2022

Description

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

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

  1. git clone https://github.com/dittos/graphql-codegen-ts-strict-repro.git
  2. npm install
  3. Apply the fix to node_modules/@graphql-codegen/plugin-helpers/oldVisit.d.ts
  4. $(npm bin)/tsc

Test Environment:

  • OS: Ubuntu 20.04.1 LTS
  • @graphql-codegen/plugin-helpers: 2.4.2
  • NodeJS: v16.13.2

Checklist:

  • I have followed the CONTRIBUTING doc and the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@changeset-bot
Copy link

changeset-bot bot commented Jun 11, 2022

🦋 Changeset detected

Latest commit: eb0f852

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@graphql-codegen/plugin-helpers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link

vercel bot commented Jun 11, 2022

@dittos is attempting to deploy a commit to the The Guild Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jul 6, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
graphql-code-generator ✅ Ready (Inspect) Visit Preview Jul 6, 2022 at 0:57AM (UTC)

Copy link
Collaborator

@n1ru4l n1ru4l left a comment

Choose a reason for hiding this comment

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

@dittos Please create a changeset for the affected package as instructed via #7931 (comment)

`Partial<T>` includes `{}`, therefore `NewVisitor[keyof NewVisitor]` includes `undefined`, and indexing `undefined` is error.

Issue: dotansimha#7519
@saihaj saihaj merged commit a4fe500 into dotansimha:master Jul 8, 2022
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.

None yet

3 participants