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

Conditional types break mapped types on arrays and tuples #29702

Closed
falsandtru opened this issue Feb 2, 2019 · 0 comments · Fixed by #29740
Closed

Conditional types break mapped types on arrays and tuples #29702

falsandtru opened this issue Feb 2, 2019 · 0 comments · Fixed by #29740
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@falsandtru
Copy link
Contributor

falsandtru commented Feb 2, 2019

cc @sandersn

TypeScript Version: 3.4.0-dev.20190131

Search Terms:

Code

type Remap1<T> = { [P in keyof T]: Remap1<T[P]>; };
type Remap2<T> = T extends object ? { [P in keyof T]: Remap2<T[P]>; } : T;
  
type a = Remap1<string[]>;
type b = Remap2<string[]>;

Expected behavior:

a type and b type are:

any[]

But this is also wrong. Must be string[].

Actual behavior:

b type is:

{
    [x: number]: string;
    length: number;
    toString: {};
    toLocaleString: {};
    pop: {};
    push: {};
    concat: {};
    join: {};
    reverse: {};
    shift: {};
    slice: {};
    sort: {};
    splice: {};
    unshift: {};
    indexOf: {};
    lastIndexOf: {};
    every: {};
    ... 13 more ...;
    includes: {};
}

Playground Link: http://www.typescriptlang.org/play/index.html#src=type%20Remap1%3CT%3E%20%3D%20%7B%20%5BP%20in%20keyof%20T%5D%3A%20Remap1%3CT%5BP%5D%3E%3B%20%7D%3B%0Atype%20Remap2%3CT%3E%20%3D%20T%20extends%20object%20%3F%20%7B%20%5BP%20in%20keyof%20T%5D%3A%20Remap2%3CT%5BP%5D%3E%3B%20%7D%20%3A%20T%3B%0A%20%20%0Atype%20a%20%3D%20Remap1%3Cstring%5B%5D%3E%3B%0Atype%20b%20%3D%20Remap2%3Cstring%5B%5D%3E%3B

Related Issues:
#29442

@falsandtru falsandtru changed the title Mapped types on arrays and tuples don't work with conditional types Conditional types break mapped types on arrays and tuples Feb 2, 2019
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Feb 4, 2019
@ahejlsberg ahejlsberg added Bug A bug in TypeScript Fixed A PR has been merged for this issue and removed Needs Investigation This issue needs a team member to investigate its status. labels Feb 6, 2019
@ahejlsberg ahejlsberg added this to the TypeScript 3.4.0 milestone Feb 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants