Skip to content

CODEGEN-479 - Fix client preset not working with exactOptionalPropertyTypes=true when documentMode=string #10373

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

Merged
merged 3 commits into from
Jun 23, 2025

Conversation

eddeee888
Copy link
Collaborator

Description

When exactOptionalPropertyTypes=true is set in tsconfig, we'd get the following error:

Class 'TypedDocumentString<TResult, TVariables>' incorrectly implements interface 'DocumentTypeDecoration<TResult, TVariables>'.
  Types of property '__apiType' are incompatible.
    Type '((variables: TVariables) => TResult) | undefined' is not assignable to type '(variables: TVariables) => TResult'.
      Type 'undefined' is not assignable to type '(variables: TVariables) => TResult'.ts(2420)

This is because DocumentTypeDecoration<TResult, TVariables>['__apiType'] type resolves to ((variables: TVariables) => TResult) | undefined but only (variables: TVariables) => TResult is valid here.

By wrapping it with NonNullable, we are removing the | undefined from DocumentTypeDecoration<TResult, TVariables>['__apiType'], meaning the implementing type now matches up.

Related #10021

Type of change

Please delete options that are not relevant.

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

How Has This Been Tested?

  • Unit test

Copy link

changeset-bot bot commented Jun 21, 2025

🦋 Changeset detected

Latest commit: 9b12d11

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/typed-document-node Patch
@graphql-codegen/client-preset 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

Copy link
Contributor

github-actions bot commented Jun 21, 2025

💻 Website Preview

The latest changes are available as preview in: https://pr-10373.graphql-code-generator.pages.dev

Copy link
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/typed-document-node 5.1.2-alpha-20250623123201-9b12d112d561982456dc33390d36ce8420987001 npm ↗︎ unpkg ↗︎
@graphql-codegen/client-preset 4.8.3-alpha-20250623123201-9b12d112d561982456dc33390d36ce8420987001 npm ↗︎ unpkg ↗︎

@eddeee888 eddeee888 merged commit c3295f9 into master Jun 23, 2025
18 checks passed
@eddeee888 eddeee888 deleted the fix-exact-optional-property-types branch June 23, 2025 12:39
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