-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Literals][Indexes][Type assertion] Is that a bug? #14093
Comments
Type assertion checks for a valid conversion from one type of the other, this can be in both directions, i.e. up/down cast. In this example, neither types is assignable to the other, so The real issue is that a string literal type in a mutable location (i.e. |
Also, |
Well I already know that but what if I want to assert like a boss (
Why? Aren't they expected to convert a variable type into provided one? |
if all what you want is to make the assignment work, assert to |
No way! |
? |
Explicit variable type declaration works well but what this issue is up to is that type assertion actually doesn't works as expected. That's why it can't be shut up just by |
Probably best to read https://basarat.gitbooks.io/typescript/content/docs/types/type-assertion.html |
Well thanks. let's read the first line:
|
Good start - keep going 😉 |
Literal types related topics & conversations
Related to this issue PR that regulates literal type inference and its behavior in self-type changing can be found here: #10676
TypeScript Version: 2.1.6
Code
Expected behavior:
Type assertion is expected to work in both cases
<>
andas
but doesn'tActual behavior:
Fails
Error:
The text was updated successfully, but these errors were encountered: