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 error inside but not outside generic function #16158

Closed
RafaelSalguero opened this issue May 30, 2017 · 2 comments
Closed

Mapped type error inside but not outside generic function #16158

RafaelSalguero opened this issue May 30, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@RafaelSalguero
Copy link

TypeScript Version: 2.3.4

Code

type MT<Keys extends string> = {
    [key in Keys]: number
}

type keys = "x" | "y";
interface Vector { x: number, y: number };

const vectorA: Vector = { x: 10, y: 20 };
const vectorB: MT<keyof Vector> = vectorA; //Correctly works
const vectorC: MT<string> = vectorB; //Correctly works
const vectorD: MT<keys> = vectorA; //Correctly works  

function MyFunc<TData extends MT<keyof TData>>(data: TData) {
    const a : TData = data;
    const b: MT<keyof TData> = a; //Correctly works
    //error!
    const c: MT<string> = b; //MT<keyof TData> is not assignable to MT<string>
}

Expected behavior:
Variable b should be assignable to c since keyof TData its a string union
Actual behavior:
Type MT<keyof TData> is not assignable to MT<string>

@ahejlsberg
Copy link
Member

Duplicate of #14548 (since, in the example above, MT<string> is effectively the same as { [key: string]: number }).

@ahejlsberg ahejlsberg added the Duplicate An existing issue was already created label May 31, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Jun 14, 2017

Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.

@mhegazy mhegazy closed this as completed Jun 14, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants