Skip to content

[typescript] fix: satisfy strict mode in typescript (#4683) - #11014

Merged
eddeee888 merged 2 commits into
masterfrom
claude/youthful-cerf-dz8xxc
Sep 30, 2026
Merged

eddeee888 merged 2 commits into
masterfrom
claude/youthful-cerf-dz8xxc

Conversation

@eddeee888

Copy link
Copy Markdown
Collaborator

Description

Part of the strict: true tracker #10985. This fixes the 19 errors plugins/typescript/typescript hits under strict mode. Instead of patching each TsVisitor override, it types the shared BaseTypesVisitor methods those overrides extend:

  • visitor-plugin-common
    • Adds NormalizedDeclarationKindConfig (Required<DeclarationKindConfig>, the same pattern as NormalizedOperationDeclarationKindConfig). It's used by DEFAULT_DECLARATION_KINDS, normalizeDeclarationKind and ParsedTypesConfig.declarationKind, because normalizing always sets every kind. This fixes TS2345 on getPunctuation.
    • Types the visitor params of NamedType, ListType, FieldDefinition, InputValueDefinition and UnionTypeDefinition. key and parent are required, because oldVisit always passes them. This fixes TS7006 and TS2538.
    • ObjectTypeDefinition, EnumTypeDefinition and DirectiveDefinition can return string | null. TsIntrospectionVisitor returns null from all three to leave types out, and the base EnumTypeDefinition already returns null for external enums. This fixes TS2416 and TS2322.
  • typescript
    • Skips document files that have no document when collecting introspection types (TS2769).
    • Types the TsVisitor visitor params.
    • Uses a || [] fallback for originalNode.types (TS18048).

Generated output is unchanged. The strict typecheck goes from 270 to 228 errors: 0 in typescript, and visitor-plugin-common drops from 196 to 173.

This is option 3 of the three options discussed (the other two were "fix it inside the package only" and "only add the shared declarationKind type"). We picked it so the base visitor signatures get fixed properly now instead of being worked around in each subclass.

Related #4683

Type of change

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

How Has This Been Tested?

  • Ran tsc --noEmit -p tsconfig.json with the tracker's strict tsconfig.json: 0 errors under plugins/typescript/typescript, and no new errors in other packages.
  • pnpm types:check (the current non-strict config) is clean.
  • vitest --project typescript --project typescript-operations --project typescript-resolvers: 530 passed, 2 skipped.

🤖 Generated with Claude Code

https://claude.ai/code/session_01UcXG2hnduGFaXB3oCtb8UX


Generated by Claude Code

Fixes the 19 errors `plugins/typescript/typescript` hits once the root
tsconfig enables `strict: true`, by typing the shared `BaseTypesVisitor`
methods `TsVisitor` overrides instead of patching each override:

- visitor-plugin-common: adds `NormalizedDeclarationKindConfig`
  (`Required<DeclarationKindConfig>`, mirroring
  `NormalizedOperationDeclarationKindConfig`) for `DEFAULT_DECLARATION_KINDS`,
  `normalizeDeclarationKind` and `ParsedTypesConfig.declarationKind`, since
  normalizing always fills every kind (TS2345 on `getPunctuation`).
  `NamedType` and `ListType` get the param types oldVisit calls them with
  (`key: string | number | undefined`, `parent: any`,
  `path: ReadonlyArray<string | number>`, `ancestors: ASTNode[]` to match
  `getVisitorKindContextFromAncestors`) (TS7006). `ObjectTypeDefinition`,
  `EnumTypeDefinition` and `DirectiveDefinition` return `string | null`:
  `TsIntrospectionVisitor` returns `null` from all three to drop types, and
  the base `EnumTypeDefinition` already returns `null` for external enums
  (TS2416, TS2322).
- typescript: skip document files without a `document` when collecting
  introspection types (TS2769), type `getMaybeWrapper`/`NamedType`/`ListType`
  params (TS7006), fall back for the optional `key` in `parent[key]` and for
  `originalNode.types` (TS2538, TS18048), and `EnumTypeDefinition` returns
  `string | null` like the introspection override (TS2322).

Generated output is unchanged. The strict typecheck goes from 270 to 229 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UcXG2hnduGFaXB3oCtb8UX

eddeee888:oss:issue-fix
…4683)

`BaseTypesVisitor`'s `FieldDefinition`, `InputValueDefinition` and
`UnionTypeDefinition` now take `key: string | number` and `parent: any`,
since oldVisit always passes them. `TsVisitor`'s overrides take them as
required too, so `parent[key]` needs no fallback.

The strict typecheck goes from 229 to 228 errors.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UcXG2hnduGFaXB3oCtb8UX
@changeset-bot

changeset-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7a0bd0d

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

This PR includes changesets to release 2 packages
Name Type
@graphql-codegen/typescript Patch
@graphql-codegen/visitor-plugin-common 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

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-codegen/visitor-plugin-common 7.2.8-alpha-20260930110015-7a0bd0df6a5943b59889a6fee5cc1bf3636a1f74 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript-operations 6.1.10-alpha-20260930110015-7a0bd0df6a5943b59889a6fee5cc1bf3636a1f74 npm ↗︎ unpkg ↗︎
@graphql-codegen/typescript 6.1.1-alpha-20260930110015-7a0bd0df6a5943b59889a6fee5cc1bf3636a1f74 npm ↗︎ unpkg ↗︎
@graphql-codegen/client-preset 6.2.1-alpha-20260930110015-7a0bd0df6a5943b59889a6fee5cc1bf3636a1f74 npm ↗︎ unpkg ↗︎
@graphql-codegen/plugin-helpers 7.4.1-alpha-20260930110015-7a0bd0df6a5943b59889a6fee5cc1bf3636a1f74 npm ↗︎ unpkg ↗︎

@eddeee888
eddeee888 marked this pull request as ready for review September 30, 2026 13:35
@eddeee888
eddeee888 merged commit 7a376ef into master Sep 30, 2026
22 checks passed
@eddeee888
eddeee888 deleted the claude/youthful-cerf-dz8xxc branch September 30, 2026 13:35
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.

2 participants