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

Update tsd (and pin TypeScript to current minor) #839

Merged
merged 13 commits into from
Apr 2, 2024
Merged

Conversation

voxpelli
Copy link
Collaborator

@voxpelli voxpelli commented Mar 20, 2024

As a preparation for #837 and as a companion to #838 I went ahead an updated tsd as well to the latest version, but turns out that the tsd tests are broken in latest version (likewise broken when rewriting to use eg. expect-type in latest typescript)

Fixes #833

@mrazauskas
Copy link

As far as I can understand, there are two failures here:

  1. As already mentioned in ReadonlyDeep / WritableDeep not modifying arrays as of TS 5.3.3 #833 (comment), tests of ReadonlyDeep / WritableDeep are failing because of a change in TypeScript Improve inference between types with multiple signatures microsoft/TypeScript#54448

  2. The failure of MergeDeep test is a bug / feature of tsd (triggered by some another change in TypeScript).

    There are numerous issues in tsd repo pointing out that types are getting inferred different, if an expression is moved outside of an assertion. In this case, type of the source argument passed to mergeDeep() is inferred by tsd assertion as (number | true)[]:

    Screenshot 2024-03-22 at 21 24 46

    , but outside of assertion it is inferred as (number | boolean)[]:

    Screenshot 2024-03-22 at 21 21 03

    This difference if cause by the fact that tsd is inferring types already knowing what result is expected. More or less like here (and this can be interpreted both as a bug or a feature):

    Screenshot 2024-03-22 at 21 19 09

I guess you saw similar issues before and this is why expect-type got involved. The following assertion is passing:

expectTypeOf(mergeDeep(['life'], [42, true], {arrayMergeMode: 'spread'})).toEqualTypeOf<Array<number | string | boolean>>();

, because type is inferred correctly (in mine and expect-types opinion):

Screenshot 2024-03-22 at 21 29 06

@voxpelli voxpelli marked this pull request as ready for review April 2, 2024 10:06
@voxpelli
Copy link
Collaborator Author

voxpelli commented Apr 2, 2024

Seems like the issue was HasMultipleCallSignatures, it always returned true, but I made a fix for that

@voxpelli
Copy link
Collaborator Author

voxpelli commented Apr 2, 2024

Needs one fix

@voxpelli
Copy link
Collaborator Author

voxpelli commented Apr 2, 2024

Now it properly detects a multiple signature like this as well:

type Overloaded2 = {
	(foo: number | undefined): string;
	(foo: number): string;
};

},
"exclude": [
// Ignore `WriteableDeep` error temporarily, remove when #833 are fixed.
"test-d/writable-deep.ts",
Copy link
Owner

Choose a reason for hiding this comment

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

Would you be able to add a test to test-d/writable-deep.ts too? So it doesn't regress again in the future.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sindresorhus Sure, there is a test already, but most tests in both of these are indirect ones which gives some cascading one, I'll add en explicit one 👍

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@sindresorhus Done ✔️

@sindresorhus sindresorhus merged commit 2878773 into main Apr 2, 2024
8 checks passed
@sindresorhus sindresorhus deleted the update-tsd branch April 2, 2024 17:18
@sindresorhus
Copy link
Owner

Great! 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 this pull request may close these issues.

ReadonlyDeep / WritableDeep not modifying arrays as of TS 5.3.3
4 participants