-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Widen union type discriminant to all compile time constants #11656
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
Comments
I'm pretty sure that |
Why types would not be a compile time constants in a statically typed language ? |
TypeScript type system is structural. so |
Whether
|
No, it is not. consider: class Calculator1 {
doWork(): Calculator1Result {
return {};
}
}
var c: Calculator1 = new Calculator1();
console.log(c instanceof Calculator1); // true
c = {
doWork() { }
};
console.log(c instanceof Calculator1); // false The type system is structural. i would recommend reading https://github.com/Microsoft/TypeScript/wiki/FAQ#what-is-structural-typing. |
Since I've read nearly all the wiki, I'm pretty much aware of the structural typing consequences. The question is: Beside this, from the Design Meeting Notes, 5/6/2016 #8503 This is good news and may affect class type comparison somehow. |
@akarzazi it is worth noting that compile time constants are generally primitive. So a |
@aluanhaddad I don't think that the member of type |
@akarzazi A value of something of the type |
@aluanhaddad
Furthermore , I don't think mutability has something todo with type narrowing.
Why the same narrowing won't work for union type discrimination ? |
TypeScript Version: 2.0.3 / nightly (2.1.0-dev.201xxxxx)
This is a suggestion
Code
Expected behavior:
Widen union discriminator to all compile time constants
Actual behavior:
Union discriminator can only be of type String Literal
The text was updated successfully, but these errors were encountered: