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

[4.10.0][Regression] failure when type checking with exactOptionalPropertyTypes #801

Closed
AviVahl opened this issue Jan 23, 2024 · 5 comments · Fixed by #804
Closed

[4.10.0][Regression] failure when type checking with exactOptionalPropertyTypes #801

AviVahl opened this issue Jan 23, 2024 · 5 comments · Fixed by #804

Comments

@AviVahl
Copy link

AviVahl commented Jan 23, 2024

mkdir show-issue
cd show-issue
npm init -y
npm i typescript type-fest -D
npx tsc --init --skipLibCheck false --target es2022 --exactOptionalPropertyTypes
echo "import 'type-fest';" > test.ts
npx tsc --noEmit

See the following error:

node_modules/type-fest/source/merge-deep.d.ts:292:50 - error TS2344: Type '{ [KeyType in keyof ({ [Key in keyof PickIndexSignature<Options> as Key extends never ? never : Key]: PickIndexSignature<Options>[Key]; } & PickIndexSignature<...> & { [Key in keyof OmitIndexSignature<...> as Key extends "spreadTopLevelArrays" ? never : Key]: OmitIndexSignature<...>[Key]; } & OmitIndexSignature<...>...' does not satisfy the constraint '{ arrayMergeMode?: ArrayMergeMode; recurseIntoArrays?: boolean; spreadTopLevelArrays?: boolean; }'.
  Types of property 'arrayMergeMode' are incompatible.
    Type 'Options["arrayMergeMode"]' is not assignable to type 'ArrayMergeMode'.
      Type 'ArrayMergeMode | undefined' is not assignable to type 'ArrayMergeMode'.
        Type 'undefined' is not assignable to type 'ArrayMergeMode'.

292     ? MergeDeepArrayOrTuple<Destination, Source, Merge<Options, {spreadTopLevelArrays: false}>>
                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/type-fest/source/merge-deep.d.ts:292

Saw first in wixplosives/core3-playground#175

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • The funding will be given to active contributors.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@sindresorhus
Copy link
Owner

// @Emiyaaaaa

@Emiyaaaaa
Copy link
Collaborator

Emiyaaaaa commented Jan 23, 2024

// @Emiyaaaaa

#802 I was tested that it's working after the revert, we can revert first.

exactOptionalPropertyTypes is false in type-fest's tsconfig, should we also support exactOptionalPropertyTypes: true?

@Emiyaaaaa
Copy link
Collaborator

Emiyaaaaa commented Jan 23, 2024

I found some interesting thing:

image

image

Seem like Merge<T, T> is {a?: T['a']} and certainty T['a'] is string | undefined,
then string | undefined is not assignable to type 'string' which is a in A, so ts throw an error

So the basic problem is that Merge<T, T> is {a?: T['a']} when T is a generic type, this maybe is a feature or rules of typescript I don't know.

In type-fest@4.9.0, Merge used EnforceOptional to convert undefined to ? and remove undefined, but in fact this is a wrong action and people reported the issue. So I removed EnforceOptional in 4.10.0.

If we need to fix tsc error when exactOptionalPropertyTypes: true, I think we can only resolve bug case-by-case like this
image

How about you think? @sindresorhus

@sindresorhus
Copy link
Owner

exactOptionalPropertyTypes is false in type-fest's tsconfig, should we also support exactOptionalPropertyTypes: true?

Yes, we should add it to our config.

@AviVahl
Copy link
Author

AviVahl commented Jan 24, 2024

Thanks! ❤️

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 a pull request may close this issue.

3 participants