- Notifications
You must be signed in to change notification settings - Fork 13.2k
Open
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
Milestone
Description
Bug Report
Hello,
🔎 Search Terms
type narrowing, generic types, control flow analysis
🕗 Version & Regression Information
(see Playground) When trying to narrow generic types (unions), the control flow analysis is not aware of the narrowing. I also see that this PR: #43183 was supposed to address this.
Please keep and fill in the line that best applies:
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about type narrowing
⏯ Playground Link
Playground link with relevant code
💻 Code
constINITIAL_STATE={1: 'test1',2: 'test2',};typeState=typeofINITIAL_STATE;conststateReducer=<TypeextendskeyofState>(state: State,action: {type: Type;value: string}|{type: 'clear';value: number},)=>{if(action.type==='clear'){// action.value is "string | number", but should be "number"returnaction.value;}return{ ...state,[action.type]: action.value,};};stateReducer(INITIAL_STATE,{type: 'clear',value: 0});🙁 Actual behavior
action.value is "string | number"
🙂 Expected behavior
but should be "number"
Thanks in advance!
jcalz, spaghettiguru, JoshuaKGoldberg, AntonioGargaro, abhithesys and 3 more
Metadata
Metadata
Assignees
Labels
Needs InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.