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

Record<string, string> is assignable to Record<T, string> #37607

Closed
bela53 opened this issue Mar 25, 2020 · 1 comment
Closed

Record<string, string> is assignable to Record<T, string> #37607

bela53 opened this issue Mar 25, 2020 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@bela53
Copy link

bela53 commented Mar 25, 2020

TypeScript Version: 3.8.3-3.9.0-dev.20200324

Search Terms:
mapped type, record, assignability, assignability compatibility, generic type, type parameter, generic mapped type, string index signature

Code

function foo<T extends string>(
    a1: Record<T, string>, a2: Record<string, string>, a3: { [P in T]: string }
): Record<T, string> {
    a2 = a1 // no error, expected
    a3 = a2 // error, expected

    a1 = a2 // no error, not expected (!)
    return a2 // no error, not expected (!)
};

Expected behavior:
a2: Record<string, string> is not assignable to a1: Record<T, string>. Also returned a2 is invalid.

Actual behavior:
a1 = a2 compiles and returned value is assignable to declared return type.

Playground Link:
here

Related Issues:
#28798

@bela53 bela53 changed the title Record<string, string> is assignable to Record<T, string> Record<string, string> is assignable to Record<T, string> Mar 25, 2020
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Mar 27, 2020
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 27, 2020
@jack-williams
Copy link
Collaborator

Duplicate of #29698, I think.

@ahejlsberg ahejlsberg added Duplicate An existing issue was already created and removed Needs Investigation This issue needs a team member to investigate its status. labels May 31, 2023
@ahejlsberg ahejlsberg removed this from the Backlog milestone May 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants