You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
consta1='A1';// as constconsta2='A2';// as constconstactionCreators={a1: ()=>({type: a1}),a2: (b)=>({type: a2, b }),};exportdefault(state={},action)=>{switch(action.type){casea2:
returnObject.assign(Object.assign({},state),{b: action.b});default:
returnstate;}};
I see... Thanks for the explanation provided in the linked PRs - but my intuition was built from IDEs type hint tooltips, neither VS Code nor IntelliJ distinguish between the 2 different types (widening and non-widening literals both look the same):
I wanted to ask where it's documented, but now that I know what to look for, I found it in mentioned in cost assertions section:
no literal types in that expression should be widened (e.g. no going from "hello" to string)
The feature was very hard to discover for me (and surprising when I did), but I understand how it makes sense I guess, so I will either get used to it or wait for a new readonly-by-default mode proposed in #32758.
my intuition was built from IDEs type hint tooltips, neither VS Code nor IntelliJ distinguish between the 2 different types (widening and non-widening literals both look the same)
Yeah, we actually discussed displaying something to distinguish between the two, but we decided against the additional noise as in most cases it doesn't matter.
TypeScript Version: 3.9.2
Search Terms:
const assertion, literal narrowing
Code
Expected behavior:
Code with literal narrowing should compile, similar to the following code with an explicit const assertion:
Actual behavior:
Code does not compile.
Related Issues:
Might be related to #9998.
Output
Compiler Options
Playground Link: Provided
The text was updated successfully, but these errors were encountered: