Skip to content

Computed properties are not type checked correctly #17975

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

Closed
Roam-Cooper opened this issue Aug 23, 2017 · 2 comments
Closed

Computed properties are not type checked correctly #17975

Roam-Cooper opened this issue Aug 23, 2017 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@Roam-Cooper
Copy link

Roam-Cooper commented Aug 23, 2017

TypeScript Version: 2.3.3

Code

let properties = {
colour: "colour" as "colour"
};

interface DataFace{
colour?: "red" | "green" | "blue";
}

let data1: DataFace = {
[properties.colour]: "yellow"
};

let data2: DataFace = {} as any;
data2[properties.colour] = "yellow";

Expected behavior:
Assignment to both data1 and data2 fails because the value yellow is not a valid value of the property colour according to the DataFace interface.

Actual behavior:
Assignment to data2 fails as expected, but assignment to data1 succeeds because it seems like weak typing + potential internal conversion of computed properties to strings means that type checking is ignored for the computed property.

@mhegazy
Copy link
Contributor

mhegazy commented Aug 23, 2017

should be covered by #16760

@mhegazy mhegazy added the Duplicate An existing issue was already created label Aug 23, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Sep 6, 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 Sep 6, 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

2 participants