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

Mapped type reported as incompatible when passed through another mapped type (5.4 regression) #58060

Closed
dragomirtitian opened this issue Apr 3, 2024 · 1 comment Β· Fixed by #58098
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.

Comments

@dragomirtitian
Copy link
Contributor

dragomirtitian commented Apr 3, 2024

πŸ”Ž Search Terms

mapped type assignability regression

πŸ•— Version & Regression Information

  • This changed between versions 5.3 and 5.4

⏯ Playground Link

Playground Link

πŸ’» Code

type ValueType = string;

type Box<T extends ValueType> = { v: T };

type Test<T extends ValueType[]> = T

type UnboxArray<T> = {
    [K in keyof T]: T[K] extends Box<infer R> ? R   : never;
};

type Identity<T> = { [K in keyof T]: T[K] };


declare function fnBad<T extends Array<Box<ValueType>>>(...args: T): Test<Identity<UnboxArray<T>>>;

declare function fnOk<T extends Array<Box<ValueType>>>(...args: T): Test<UnboxArray<T>>;


type Unbox<T> = T extends Array<Box<infer R>> ? Array<R> : never;
declare function fnSimilar<T extends Array<Box<ValueType>>>(...args: T): Test<Identity<Unbox<T>>>;

πŸ™ Actual behavior

Test<Identity<UnboxArray<T>>> is being reported as an error because Identity<UnboxArray<T>> is not assignable to the constraint of Test. Even more strange the error elaboration says Type 'Box<string>' is not assignable to type 'string' which is strange since the type that comes out of UnboxArray<T> can't have Box<string> as an item type. If we don't pass the type though the Identity mapped type, then UnboxArray<T> is assignable to ValueType[].

πŸ™‚ Expected behavior

Test<Identity<UnboxArray<T>>> should not be an error as it is in 5.3

Additional information about the issue

No response

@jakebailey
Copy link
Member

Bisects to #57122. @ahejlsberg

@ahejlsberg ahejlsberg self-assigned this Apr 5, 2024
@ahejlsberg ahejlsberg added Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript. labels Apr 7, 2024
@ahejlsberg ahejlsberg added this to the TypeScript 5.4.4 milestone Apr 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Recent Regression This is a new regression just found in the last major/minor version of TypeScript.
Projects
None yet
4 participants