Bug Report
It seems to me that type for primitive value assigned to a const variable gets widened in some contexts - I'm not 100% sure if this is a bug report or feature request, but this is a bit counterintuitive. Is this an expected behaviour?
(From what I saw in the playground hints, primitive values assigned to const behave as if they had as const modifier)
🔎 Search Terms
primitive value
primitive widening
⏯ Playground Link
Playground link with relevant code
💻 Code
The hint shows the TYPE_1 is not string:

constTYPE_1='TYPE_1';constTYPE_2='TYPE_2';constTYPE_3='TYPE_3'asconst;constTYPE_4='TYPE_4'asconst;constaction1=()=>({type: TYPE_1});constaction2=()=>({type: TYPE_2,payload: {}});constaction3=()=>({type: TYPE_3});constaction4=()=>({type: TYPE_4,payload: {}});typeNonConstTypeActions=|ReturnType<typeofaction1>|ReturnType<typeofaction2>;typeConstTypeActions=|ReturnType<typeofaction3>|ReturnType<typeofaction4>;functionnonConstTypesReducer(state: {},action: NonConstTypeActions){switch(action.type){caseTYPE_2:
returnaction.payload;// Property 'payload' does not exist on type 'NonConstTypeActions'.default:
return{};}}functionwithConstTypesReducer(state: {},action: ConstTypeActions){switch(action.type){caseTYPE_4:
returnaction.payload;default:
return{};}}🙁 Actual behavior
Type guard wasn't able to narrow down a type because field type got widened to string.
🙂 Expected behavior
Both examples should pass
Bug Report
It seems to me that type for primitive value assigned to a const variable gets widened in some contexts - I'm not 100% sure if this is a bug report or feature request, but this is a bit counterintuitive. Is this an expected behaviour?
(From what I saw in the playground hints, primitive values assigned to
constbehave as if they hadas constmodifier)🔎 Search Terms
primitive value
primitive widening
⏯ Playground Link
Playground link with relevant code
💻 Code
The hint shows the

TYPE_1is not string:🙁 Actual behavior
Type guard wasn't able to narrow down a type because field type got widened to
string.🙂 Expected behavior
Both examples should pass