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
{{ message }}
Repository navigation
Object with all context-sensitive properties requires at least one non-context-sensitive property for inference to workย #64251
// problem: doesn't infer D correctly, context and state are anycreateMachine({initial: "a",context: {foo: 1},states: {a: {entry: (context,state)=>{context// ^? anystate// ^? any}}}})// solution: add a useless non-context-sensitive property `_: null` createMachine({initial: "a",context: {foo: 1},states: {a: {entry: (context,state)=>{context// ^? { foo: number }state// ^? "a"},_: null}}})declareconstcreateMachine:
<Dextends{initial: keyofD["states"],context: object,states: {[SinkeyofD["states"]]: {entry?: (context: D["context"],state: S)=>void,_?: null}}}>(definition: IdentityObject<D>)=>DtypeIdentity<T>=Textendsany
? (Textends(...a: never)=>unknown ? T :
Textendsobject ? IdentityObject<T> :
T)
: nevertypeIdentityObject<T>={[KinkeyofT]: Identity<T[K]>}
๐ Actual behavior
The first createMachine invocation doesn't infer the type parameter correctly (it requires at least one non-context-sensitive property) and hence context and state parameters of entry are not inferred.
๐ Expected behavior
The first createMachine invocation should infer the type parameter correctly without having to pass in a non-context-sensitive property leading to inference of context and state parameters of entry
Additional information about the issue
The premise is adding (or rather not adding) an extra useless property shouldn't make a difference to the inference
#54029 would resolve this issue already here - so it's kinda strong duplicate of #48798 . That said... #54029 doesn't resolve all cases and I'm cooking up a revised PR of that for TS Go. Stay tuned ๐
Mateusz Burzyลski (@Andarist) Nice... A bit of a trivia / fyi given you took this problem out of txstate (linking for others), this whole Identity (or InferNarrowest) is actually a workaround... so even if this reverse mapped type issue is resolved, it's still not enough to type abstractions like xstate, for that we need #64091, eg I'd be curious if you can type this with your PR... But then again any progress is good!
Activity
RyanCavanaugh commentedon Sep 14, 2026
Mateusz Burzyลski (@Andarist) any thoughts (on this or the PR) ?
RyanCavanaugh commentedon Sep 14, 2026
Copilot cites #48798 as prior work in this area, with #54029 as a superset of the linked PR
Andarist commentedon Sep 16, 2026
#54029 would resolve this issue already here - so it's kinda strong duplicate of #48798 . That said... #54029 doesn't resolve all cases and I'm cooking up a revised PR of that for TS Go. Stay tuned ๐
devanshj commentedon Sep 17, 2026
Mateusz Burzyลski (@Andarist) Nice... A bit of a trivia / fyi given you took this problem out of txstate (linking for others), this whole
Identity(orInferNarrowest) is actually a workaround... so even if this reverse mapped type issue is resolved, it's still not enough to type abstractions like xstate, for that we need #64091, eg I'd be curious if you can type this with your PR... But then again any progress is good!