Skip to content

Infer string literals types in const declarations - #5796

Closed
Daniel Rosenwasser (DanielRosenwasser) wants to merge 10 commits into
masterfrom
inferStringLiteralsForConst
Closed

Daniel Rosenwasser (DanielRosenwasser) wants to merge 10 commits into
masterfrom
inferStringLiteralsForConst

Conversation

@DanielRosenwasser

Copy link
Copy Markdown
Member

This PR experimentally adds functionality so that string literals are given string literal types in const declarations. It is the first step towards exploring "mutability widening" as brought up in the design meeting.

@mhegazy

Copy link
Copy Markdown
Contributor

this still does not answer cases like:

const blue = "blue";
const red= "red";

let color = blue;
if (Math.random()) {
    color = red; /// Error !
}

in #5740 we talked about handling let and const differently, and allowing for different widening rules.

@DanielRosenwasser

Copy link
Copy Markdown
Member Author

I don't think this is the right thing to do for now.

@mhegazy
Mohamed Hegazy (mhegazy) deleted the inferStringLiteralsForConst branch November 2, 2017 21:02
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants