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
exportenumTRANSITIONS{A='a',B='b',}exportenumSTATES{ONE='one',TWO='two',}exportclassStateOneObject{doSomething(){}}exportclassStateTwoObject{doSomething(){}}exporttypeStatesToObjects={[STATES.ONE]: StateOneObject;[STATES.TWO]: StateTwoObject;};exportconstALLOWED_STATES_FROM_TRANSITION={[TRANSITIONS.A]: [STATES.ONE,STATES.TWO],[TRANSITIONS.B]: [STATES.ONE],}asconst;functiontest<FromTransitionextendsTRANSITIONS>(transition: FromTransition,possibilites: {[FromStateintypeofALLOWED_STATES_FROM_TRANSITION[FromTransition][number]]: (state: StatesToObjects[FromState],)=>any;},){}// Typing / Intellisense is not working // None of them worktest(TRANSITIONS.A,{// state is any but it should be StateOneObjectone: state=>{returnstate},// state is any but it should be StateTwoObjecttwo: state=>{returnstate}})// Only works the first onetest(TRANSITIONS.A,{// State is StateOneObject but state two is missing, normal errorone: state=>{returnstate.doSomething()},})// There is only one possibility but it doesn't worktest(TRANSITIONS.B,{// state is any but it should be StateOneObjectone: state=>{returnstate},})
🙁 Actual behavior
Function state param shows error when adding the second state to the object. Please do hover over the state param.
🙂 Expected behavior
The state should be from the expected type
The text was updated successfully, but these errors were encountered:
The issue here is that generic mapped types as contextual types are not being instantiated during inference (we check for TypeFlags.Instantiable instead of using isGenericType(...)). Should be fixable, but there's always a chance that breaks something else.
On closer inspection, I take back what I said about instantiation of contextual mapped types. That's actually not the issue.
It turns out your example works with the nightly build as long as you consistently use your string-based enum types in property names (your example uses regular property names in places where they should be string-based enum names). Specifically:
test(TRANSITIONS.A,{// state is StateOneObject[STATES.ONE]: state=>{returnstate},// state is StateTwoObject[STATES.TWO]: state=>{returnstate}})
However, this unfortunately doesn't work in 4.5 or earlier releases. For those, the best work-around I can recommend is to eliminate the STATES enum and instead just use string literals:
Bug Report
🔎 Search Terms
Inference Lost, function params map
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
Function state param shows error when adding the second state to the object. Please do hover over the state param.
🙂 Expected behavior
The state should be from the expected type
The text was updated successfully, but these errors were encountered: