From dea6ec45c3af7e70c440e8b2e0641460626ce3a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 25 Apr 2022 14:56:23 +0200 Subject: [PATCH 1/8] Instantiate conditional types within contextual type instantiation --- src/compiler/checker.ts | 2 +- ...lInnerCallFromConditionalContextualType.js | 49 +++++++++ ...rCallFromConditionalContextualType.symbols | 103 ++++++++++++++++++ ...nerCallFromConditionalContextualType.types | 89 +++++++++++++++ ...lInnerCallFromConditionalContextualType.ts | 39 +++++++ 5 files changed, 281 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/contextualInnerCallFromConditionalContextualType.js create mode 100644 tests/baselines/reference/contextualInnerCallFromConditionalContextualType.symbols create mode 100644 tests/baselines/reference/contextualInnerCallFromConditionalContextualType.types create mode 100644 tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 477851cc4e299..b756010f7522c 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27001,7 +27001,7 @@ namespace ts { if (inferenceContext && some(inferenceContext.inferences, hasInferenceCandidates)) { // For contextual signatures we incorporate all inferences made so far, e.g. from return // types as well as arguments to the left in a function call. - if (contextFlags && contextFlags & ContextFlags.Signature) { + if (contextFlags && contextFlags & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional)) { return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper); } // For other purposes (e.g. determining whether to produce literal types) we only diff --git a/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.js b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.js new file mode 100644 index 0000000000000..aba909dd15ea2 --- /dev/null +++ b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.js @@ -0,0 +1,49 @@ +//// [contextualInnerCallFromConditionalContextualType.ts] +interface EventObject { type: string; } +interface TypegenDisabled { "@@xstate/typegen": false; } +interface TypegenEnabled { "@@xstate/typegen": true; } + +type TypegenConstraint = TypegenEnabled | TypegenDisabled; + +interface ActionObject { + type: string; + _TE?: TEvent; +} + +declare function assign( + assignment: (ev: TEvent) => void +): ActionObject; + +declare function createMachine< + TTypesMeta extends TypegenConstraint = TypegenDisabled +>( + config: { + types?: TTypesMeta; + }, + action?: TTypesMeta extends TypegenEnabled + ? { action: ActionObject<{ type: "WITH_TYPEGEN" }> } + : { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> } +): void; + +createMachine( + { + types: {} as TypegenEnabled, + }, + { + action: assign((event) => { + event.type // should be 'WITH_TYPEGEN' + }), + } +); + + + +//// [contextualInnerCallFromConditionalContextualType.js] +"use strict"; +createMachine({ + types: {} +}, { + action: assign(function (event) { + event.type; // should be 'WITH_TYPEGEN' + }) +}); diff --git a/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.symbols b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.symbols new file mode 100644 index 0000000000000..aa55a2afebebc --- /dev/null +++ b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.symbols @@ -0,0 +1,103 @@ +=== tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts === +interface EventObject { type: string; } +>EventObject : Symbol(EventObject, Decl(contextualInnerCallFromConditionalContextualType.ts, 0, 0)) +>type : Symbol(EventObject.type, Decl(contextualInnerCallFromConditionalContextualType.ts, 0, 23)) + +interface TypegenDisabled { "@@xstate/typegen": false; } +>TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromConditionalContextualType.ts, 0, 39)) +>"@@xstate/typegen" : Symbol(TypegenDisabled["@@xstate/typegen"], Decl(contextualInnerCallFromConditionalContextualType.ts, 1, 27)) + +interface TypegenEnabled { "@@xstate/typegen": true; } +>TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromConditionalContextualType.ts, 1, 56)) +>"@@xstate/typegen" : Symbol(TypegenEnabled["@@xstate/typegen"], Decl(contextualInnerCallFromConditionalContextualType.ts, 2, 26)) + +type TypegenConstraint = TypegenEnabled | TypegenDisabled; +>TypegenConstraint : Symbol(TypegenConstraint, Decl(contextualInnerCallFromConditionalContextualType.ts, 2, 54)) +>TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromConditionalContextualType.ts, 1, 56)) +>TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromConditionalContextualType.ts, 0, 39)) + +interface ActionObject { +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromConditionalContextualType.ts, 4, 58)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType.ts, 6, 23)) +>EventObject : Symbol(EventObject, Decl(contextualInnerCallFromConditionalContextualType.ts, 0, 0)) + + type: string; +>type : Symbol(ActionObject.type, Decl(contextualInnerCallFromConditionalContextualType.ts, 6, 52)) + + _TE?: TEvent; +>_TE : Symbol(ActionObject._TE, Decl(contextualInnerCallFromConditionalContextualType.ts, 7, 15)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType.ts, 6, 23)) +} + +declare function assign( +>assign : Symbol(assign, Decl(contextualInnerCallFromConditionalContextualType.ts, 9, 1)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType.ts, 11, 24)) +>EventObject : Symbol(EventObject, Decl(contextualInnerCallFromConditionalContextualType.ts, 0, 0)) + + assignment: (ev: TEvent) => void +>assignment : Symbol(assignment, Decl(contextualInnerCallFromConditionalContextualType.ts, 11, 52)) +>ev : Symbol(ev, Decl(contextualInnerCallFromConditionalContextualType.ts, 12, 15)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType.ts, 11, 24)) + +): ActionObject; +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromConditionalContextualType.ts, 4, 58)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType.ts, 11, 24)) + +declare function createMachine< +>createMachine : Symbol(createMachine, Decl(contextualInnerCallFromConditionalContextualType.ts, 13, 24)) + + TTypesMeta extends TypegenConstraint = TypegenDisabled +>TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromConditionalContextualType.ts, 15, 31)) +>TypegenConstraint : Symbol(TypegenConstraint, Decl(contextualInnerCallFromConditionalContextualType.ts, 2, 54)) +>TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromConditionalContextualType.ts, 0, 39)) + +>( + config: { +>config : Symbol(config, Decl(contextualInnerCallFromConditionalContextualType.ts, 17, 2)) + + types?: TTypesMeta; +>types : Symbol(types, Decl(contextualInnerCallFromConditionalContextualType.ts, 18, 11)) +>TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromConditionalContextualType.ts, 15, 31)) + + }, + action?: TTypesMeta extends TypegenEnabled +>action : Symbol(action, Decl(contextualInnerCallFromConditionalContextualType.ts, 20, 4)) +>TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromConditionalContextualType.ts, 15, 31)) +>TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromConditionalContextualType.ts, 1, 56)) + + ? { action: ActionObject<{ type: "WITH_TYPEGEN" }> } +>action : Symbol(action, Decl(contextualInnerCallFromConditionalContextualType.ts, 22, 7)) +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromConditionalContextualType.ts, 4, 58)) +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType.ts, 22, 30)) + + : { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> } +>action : Symbol(action, Decl(contextualInnerCallFromConditionalContextualType.ts, 23, 7)) +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromConditionalContextualType.ts, 4, 58)) +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType.ts, 23, 30)) + +): void; + +createMachine( +>createMachine : Symbol(createMachine, Decl(contextualInnerCallFromConditionalContextualType.ts, 13, 24)) + { + types: {} as TypegenEnabled, +>types : Symbol(types, Decl(contextualInnerCallFromConditionalContextualType.ts, 27, 3)) +>TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromConditionalContextualType.ts, 1, 56)) + + }, + { + action: assign((event) => { +>action : Symbol(action, Decl(contextualInnerCallFromConditionalContextualType.ts, 30, 3)) +>assign : Symbol(assign, Decl(contextualInnerCallFromConditionalContextualType.ts, 9, 1)) +>event : Symbol(event, Decl(contextualInnerCallFromConditionalContextualType.ts, 31, 20)) + + event.type // should be 'WITH_TYPEGEN' +>event.type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType.ts, 22, 30)) +>event : Symbol(event, Decl(contextualInnerCallFromConditionalContextualType.ts, 31, 20)) +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType.ts, 22, 30)) + + }), + } +); + + diff --git a/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.types b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.types new file mode 100644 index 0000000000000..6a1ea7e19707f --- /dev/null +++ b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.types @@ -0,0 +1,89 @@ +=== tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts === +interface EventObject { type: string; } +>type : string + +interface TypegenDisabled { "@@xstate/typegen": false; } +>"@@xstate/typegen" : false +>false : false + +interface TypegenEnabled { "@@xstate/typegen": true; } +>"@@xstate/typegen" : true +>true : true + +type TypegenConstraint = TypegenEnabled | TypegenDisabled; +>TypegenConstraint : TypegenDisabled | TypegenEnabled + +interface ActionObject { + type: string; +>type : string + + _TE?: TEvent; +>_TE : TEvent | undefined +} + +declare function assign( +>assign : (assignment: (ev: TEvent) => void) => ActionObject + + assignment: (ev: TEvent) => void +>assignment : (ev: TEvent) => void +>ev : TEvent + +): ActionObject; + +declare function createMachine< +>createMachine : (config: { types?: TTypesMeta;}, action?: TTypesMeta extends TypegenEnabled ? { action: ActionObject<{ type: "WITH_TYPEGEN"; }>;} : { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>;}) => void + + TTypesMeta extends TypegenConstraint = TypegenDisabled +>( + config: { +>config : { types?: TTypesMeta | undefined; } + + types?: TTypesMeta; +>types : TTypesMeta | undefined + + }, + action?: TTypesMeta extends TypegenEnabled +>action : (TTypesMeta extends TypegenEnabled ? { action: ActionObject<{ type: "WITH_TYPEGEN";}>; } : { action: ActionObject<{ type: "WITHOUT_TYPEGEN";}>; }) | undefined + + ? { action: ActionObject<{ type: "WITH_TYPEGEN" }> } +>action : ActionObject<{ type: "WITH_TYPEGEN"; }> +>type : "WITH_TYPEGEN" + + : { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> } +>action : ActionObject<{ type: "WITHOUT_TYPEGEN"; }> +>type : "WITHOUT_TYPEGEN" + +): void; + +createMachine( +>createMachine( { types: {} as TypegenEnabled, }, { action: assign((event) => { event.type // should be 'WITH_TYPEGEN' }), }) : void +>createMachine : (config: { types?: TTypesMeta | undefined; }, action?: (TTypesMeta extends TypegenEnabled ? { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; } : { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>; }) | undefined) => void + { +>{ types: {} as TypegenEnabled, } : { types: TypegenEnabled; } + + types: {} as TypegenEnabled, +>types : TypegenEnabled +>{} as TypegenEnabled : TypegenEnabled +>{} : {} + + }, + { +>{ action: assign((event) => { event.type // should be 'WITH_TYPEGEN' }), } : { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; } + + action: assign((event) => { +>action : ActionObject<{ type: "WITH_TYPEGEN"; }> +>assign((event) => { event.type // should be 'WITH_TYPEGEN' }) : ActionObject<{ type: "WITH_TYPEGEN"; }> +>assign : (assignment: (ev: TEvent) => void) => ActionObject +>(event) => { event.type // should be 'WITH_TYPEGEN' } : (event: { type: "WITH_TYPEGEN"; }) => void +>event : { type: "WITH_TYPEGEN"; } + + event.type // should be 'WITH_TYPEGEN' +>event.type : "WITH_TYPEGEN" +>event : { type: "WITH_TYPEGEN"; } +>type : "WITH_TYPEGEN" + + }), + } +); + + diff --git a/tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts b/tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts new file mode 100644 index 0000000000000..edd7ac7425e8e --- /dev/null +++ b/tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts @@ -0,0 +1,39 @@ +// @strict: true + +interface EventObject { type: string; } +interface TypegenDisabled { "@@xstate/typegen": false; } +interface TypegenEnabled { "@@xstate/typegen": true; } + +type TypegenConstraint = TypegenEnabled | TypegenDisabled; + +interface ActionObject { + type: string; + _TE?: TEvent; +} + +declare function assign( + assignment: (ev: TEvent) => void +): ActionObject; + +declare function createMachine< + TTypesMeta extends TypegenConstraint = TypegenDisabled +>( + config: { + types?: TTypesMeta; + }, + action?: TTypesMeta extends TypegenEnabled + ? { action: ActionObject<{ type: "WITH_TYPEGEN" }> } + : { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> } +): void; + +createMachine( + { + types: {} as TypegenEnabled, + }, + { + action: assign((event) => { + event.type // should be 'WITH_TYPEGEN' + }), + } +); + From 46c1529f060ec9cd1a8047ceae1a979f4b3dedfd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 30 Sep 2022 11:10:01 +0200 Subject: [PATCH 2/8] Only instantiate the contextual conditional type if there are inference candidates --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e489eb93ad42f..65a2bf06ac179 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27534,7 +27534,7 @@ namespace ts { const inferenceContext = getInferenceContext(node); // If no inferences have been made, nothing is gained from instantiating as type parameters // would just be replaced with their defaults similar to the apparent type. - if (inferenceContext && (contextFlags! & ContextFlags.Signature && some(inferenceContext.inferences, hasInferenceCandidates) || maybeTypeOfKind(contextualType, TypeFlags.Conditional))) { + if (inferenceContext && ((contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional)) && some(inferenceContext.inferences, hasInferenceCandidates))) { // For contextual signatures we incorporate all inferences made so far, e.g. from return // types as well as arguments to the left in a function call. return instantiateInstantiableTypes(contextualType, inferenceContext.nonFixingMapper); From 715542ef2fc792d1a66b77d3f0a30d0251d77bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 30 Sep 2022 16:51:30 +0200 Subject: [PATCH 3/8] Instantiate contextual indexed access types with inference candidates too --- src/compiler/checker.ts | 2 +- ...tualInnerCallFromIndexedAccessType.symbols | 106 ++++++++++++++++++ ...extualInnerCallFromIndexedAccessType.types | 90 +++++++++++++++ ...lInnerCallFromConditionalContextualType.ts | 1 + ...ntextualInnerCallFromIndexedAccessType.ts} | 26 ++--- 5 files changed, 207 insertions(+), 18 deletions(-) create mode 100644 tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols create mode 100644 tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types rename tests/{baselines/reference/contextualInnerCallFromConditionalContextualType.js => cases/compiler/contextualInnerCallFromIndexedAccessType.ts} (52%) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 7e621f6c776a6..69cbab0d1d446 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27601,7 +27601,7 @@ namespace ts { // replaced with their constraints similar to the apparent type. if ( inferenceContext && - (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional)) && + (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional) || maybeTypeOfKind(contextualType, TypeFlags.IndexedAccess)) && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault) ) { // For contextual signatures we incorporate all inferences made so far, e.g. from return diff --git a/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols b/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols new file mode 100644 index 0000000000000..ac858cc664e18 --- /dev/null +++ b/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols @@ -0,0 +1,106 @@ +=== tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts === +interface EventObject { type: string; } +>EventObject : Symbol(EventObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 0)) +>type : Symbol(EventObject.type, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 23)) + +interface TypegenDisabled { "@@xstate/typegen": 0; } +>TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 39)) +>"@@xstate/typegen" : Symbol(TypegenDisabled["@@xstate/typegen"], Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 27)) + +interface TypegenEnabled { "@@xstate/typegen": 1; } +>TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 52)) +>"@@xstate/typegen" : Symbol(TypegenEnabled["@@xstate/typegen"], Decl(contextualInnerCallFromIndexedAccessType.ts, 2, 26)) + +type TypegenConstraint = TypegenEnabled | TypegenDisabled; +>TypegenConstraint : Symbol(TypegenConstraint, Decl(contextualInnerCallFromIndexedAccessType.ts, 2, 51)) +>TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 52)) +>TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 39)) + +interface ActionObject { +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 6, 23)) +>EventObject : Symbol(EventObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 0)) + + type: string; +>type : Symbol(ActionObject.type, Decl(contextualInnerCallFromIndexedAccessType.ts, 6, 52)) + + _TE?: TEvent; +>_TE : Symbol(ActionObject._TE, Decl(contextualInnerCallFromIndexedAccessType.ts, 7, 15)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 6, 23)) +} + +declare function assign( +>assign : Symbol(assign, Decl(contextualInnerCallFromIndexedAccessType.ts, 9, 1)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 24)) +>EventObject : Symbol(EventObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 0)) + + assignment: (ev: TEvent) => void +>assignment : Symbol(assignment, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 52)) +>ev : Symbol(ev, Decl(contextualInnerCallFromIndexedAccessType.ts, 12, 15)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 24)) + +): ActionObject; +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 24)) + +declare function createMachine< +>createMachine : Symbol(createMachine, Decl(contextualInnerCallFromIndexedAccessType.ts, 13, 24)) + + TTypesMeta extends TypegenConstraint = TypegenDisabled +>TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromIndexedAccessType.ts, 15, 31)) +>TypegenConstraint : Symbol(TypegenConstraint, Decl(contextualInnerCallFromIndexedAccessType.ts, 2, 51)) +>TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 39)) + +>( + config: { +>config : Symbol(config, Decl(contextualInnerCallFromIndexedAccessType.ts, 17, 2)) + + types?: TTypesMeta; +>types : Symbol(types, Decl(contextualInnerCallFromIndexedAccessType.ts, 18, 11)) +>TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromIndexedAccessType.ts, 15, 31)) + + }, + action?: { +>action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 20, 4)) + + 1: { action: ActionObject<{ type: "WITH_TYPEGEN" }> }; +>1 : Symbol(1, Decl(contextualInnerCallFromIndexedAccessType.ts, 21, 12)) +>action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 8)) +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) +>type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 31)) + + 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> }; +>0 : Symbol(0, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 58)) +>action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 23, 8)) +>ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) +>type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 23, 31)) + + }[TTypesMeta["@@xstate/typegen"]] +>TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromIndexedAccessType.ts, 15, 31)) + +): void; + +createMachine( +>createMachine : Symbol(createMachine, Decl(contextualInnerCallFromIndexedAccessType.ts, 13, 24)) + { + types: {} as TypegenEnabled, +>types : Symbol(types, Decl(contextualInnerCallFromIndexedAccessType.ts, 28, 3)) +>TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 52)) + + }, + { + action: assign((event) => { +>action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 31, 3)) +>assign : Symbol(assign, Decl(contextualInnerCallFromIndexedAccessType.ts, 9, 1)) +>event : Symbol(event, Decl(contextualInnerCallFromIndexedAccessType.ts, 32, 20)) + + event.type // should be 'WITH_TYPEGEN' +>event.type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 31)) +>event : Symbol(event, Decl(contextualInnerCallFromIndexedAccessType.ts, 32, 20)) +>type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 31)) + + }), + } +); + + diff --git a/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types b/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types new file mode 100644 index 0000000000000..38d79b3befb66 --- /dev/null +++ b/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types @@ -0,0 +1,90 @@ +=== tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts === +interface EventObject { type: string; } +>type : string + +interface TypegenDisabled { "@@xstate/typegen": 0; } +>"@@xstate/typegen" : 0 + +interface TypegenEnabled { "@@xstate/typegen": 1; } +>"@@xstate/typegen" : 1 + +type TypegenConstraint = TypegenEnabled | TypegenDisabled; +>TypegenConstraint : TypegenDisabled | TypegenEnabled + +interface ActionObject { + type: string; +>type : string + + _TE?: TEvent; +>_TE : TEvent | undefined +} + +declare function assign( +>assign : (assignment: (ev: TEvent) => void) => ActionObject + + assignment: (ev: TEvent) => void +>assignment : (ev: TEvent) => void +>ev : TEvent + +): ActionObject; + +declare function createMachine< +>createMachine : (config: { types?: TTypesMeta;}, action?: { 1: { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; }; 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>; };}[TTypesMeta["@@xstate/typegen"]]) => void + + TTypesMeta extends TypegenConstraint = TypegenDisabled +>( + config: { +>config : { types?: TTypesMeta | undefined; } + + types?: TTypesMeta; +>types : TTypesMeta | undefined + + }, + action?: { +>action : { 1: { action: ActionObject<{ type: "WITH_TYPEGEN"; }>;}; 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>;}; }[TTypesMeta["@@xstate/typegen"]] | undefined + + 1: { action: ActionObject<{ type: "WITH_TYPEGEN" }> }; +>1 : { action: ActionObject<{ type: "WITH_TYPEGEN";}>; } +>action : ActionObject<{ type: "WITH_TYPEGEN"; }> +>type : "WITH_TYPEGEN" + + 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> }; +>0 : { action: ActionObject<{ type: "WITHOUT_TYPEGEN";}>; } +>action : ActionObject<{ type: "WITHOUT_TYPEGEN"; }> +>type : "WITHOUT_TYPEGEN" + + }[TTypesMeta["@@xstate/typegen"]] +): void; + +createMachine( +>createMachine( { types: {} as TypegenEnabled, }, { action: assign((event) => { event.type // should be 'WITH_TYPEGEN' }), }) : void +>createMachine : (config: { types?: TTypesMeta | undefined; }, action?: { 1: { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; }; 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>; }; }[TTypesMeta["@@xstate/typegen"]] | undefined) => void + { +>{ types: {} as TypegenEnabled, } : { types: TypegenEnabled; } + + types: {} as TypegenEnabled, +>types : TypegenEnabled +>{} as TypegenEnabled : TypegenEnabled +>{} : {} + + }, + { +>{ action: assign((event) => { event.type // should be 'WITH_TYPEGEN' }), } : { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; } + + action: assign((event) => { +>action : ActionObject<{ type: "WITH_TYPEGEN"; }> +>assign((event) => { event.type // should be 'WITH_TYPEGEN' }) : ActionObject<{ type: "WITH_TYPEGEN"; }> +>assign : (assignment: (ev: TEvent) => void) => ActionObject +>(event) => { event.type // should be 'WITH_TYPEGEN' } : (event: { type: "WITH_TYPEGEN"; }) => void +>event : { type: "WITH_TYPEGEN"; } + + event.type // should be 'WITH_TYPEGEN' +>event.type : "WITH_TYPEGEN" +>event : { type: "WITH_TYPEGEN"; } +>type : "WITH_TYPEGEN" + + }), + } +); + + diff --git a/tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts b/tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts index edd7ac7425e8e..40b5ad1772ce3 100644 --- a/tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts +++ b/tests/cases/compiler/contextualInnerCallFromConditionalContextualType.ts @@ -1,4 +1,5 @@ // @strict: true +// @noEmit: true interface EventObject { type: string; } interface TypegenDisabled { "@@xstate/typegen": false; } diff --git a/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.js b/tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts similarity index 52% rename from tests/baselines/reference/contextualInnerCallFromConditionalContextualType.js rename to tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts index aba909dd15ea2..f8ff53a042b4a 100644 --- a/tests/baselines/reference/contextualInnerCallFromConditionalContextualType.js +++ b/tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts @@ -1,7 +1,9 @@ -//// [contextualInnerCallFromConditionalContextualType.ts] +// @strict: true +// @noEmit: true + interface EventObject { type: string; } -interface TypegenDisabled { "@@xstate/typegen": false; } -interface TypegenEnabled { "@@xstate/typegen": true; } +interface TypegenDisabled { "@@xstate/typegen": 0; } +interface TypegenEnabled { "@@xstate/typegen": 1; } type TypegenConstraint = TypegenEnabled | TypegenDisabled; @@ -20,9 +22,10 @@ declare function createMachine< config: { types?: TTypesMeta; }, - action?: TTypesMeta extends TypegenEnabled - ? { action: ActionObject<{ type: "WITH_TYPEGEN" }> } - : { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> } + action?: { + 1: { action: ActionObject<{ type: "WITH_TYPEGEN" }> }; + 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> }; + }[TTypesMeta["@@xstate/typegen"]] ): void; createMachine( @@ -36,14 +39,3 @@ createMachine( } ); - - -//// [contextualInnerCallFromConditionalContextualType.js] -"use strict"; -createMachine({ - types: {} -}, { - action: assign(function (event) { - event.type; // should be 'WITH_TYPEGEN' - }) -}); From 0389987a06eef3bd83361441f649616b55f4b2a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Fri, 30 Sep 2022 17:07:22 +0200 Subject: [PATCH 4/8] Allow `maybeTypeOfKind` to check if the type is any of the given types --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 69cbab0d1d446..8b9f9ee684aab 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27601,7 +27601,7 @@ namespace ts { // replaced with their constraints similar to the apparent type. if ( inferenceContext && - (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional) || maybeTypeOfKind(contextualType, TypeFlags.IndexedAccess)) && + (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional | TypeFlags.IndexedAccess)) && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault) ) { // For contextual signatures we incorporate all inferences made so far, e.g. from return @@ -33914,7 +33914,7 @@ namespace ts { // Return true if type might be of the given kind. A union or intersection type might be of a given // kind if at least one constituent type is of the given kind. function maybeTypeOfKind(type: Type, kind: TypeFlags): boolean { - if (type.flags & kind) { + if ((type.flags & kind) !== 0) { return true; } if (type.flags & TypeFlags.UnionOrIntersection) { From 9e69d6f561b3af5cfdefbd52b5d7c2fd3d196d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 18 Oct 2022 10:30:20 +0200 Subject: [PATCH 5/8] Use `TypeFlags.Simplifiable` instead of hand-written bits --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 356bdcb66787b..c1f2200ada6bd 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -27605,7 +27605,7 @@ namespace ts { // replaced with their constraints similar to the apparent type. if ( inferenceContext && - (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional | TypeFlags.IndexedAccess)) && + (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Simplifiable)) && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault) ) { // For contextual signatures we incorporate all inferences made so far, e.g. from return From d87e2cb9e06b6d9b93d74d3a8ba9684e3d2e2819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Tue, 18 Oct 2022 10:31:52 +0200 Subject: [PATCH 6/8] Revert "Allow `maybeTypeOfKind` to check if the type is any of the given types" This reverts commit 0389987a06eef3bd83361441f649616b55f4b2a4. --- src/compiler/checker.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c1f2200ada6bd..f0509c56510d5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -33928,7 +33928,7 @@ namespace ts { // Return true if type might be of the given kind. A union or intersection type might be of a given // kind if at least one constituent type is of the given kind. function maybeTypeOfKind(type: Type, kind: TypeFlags): boolean { - if ((type.flags & kind) !== 0) { + if (type.flags & kind) { return true; } if (type.flags & TypeFlags.UnionOrIntersection) { From 3ef4cf88ccf4928dc3be40d960c07fb3d8cd8177 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sat, 17 Jun 2023 23:07:52 +0200 Subject: [PATCH 7/8] add an extra test case --- ...CallFromConditionalContextualType2.symbols | 164 ++++++++++++++++++ ...erCallFromConditionalContextualType2.types | 144 +++++++++++++++ ...InnerCallFromConditionalContextualType2.ts | 65 +++++++ 3 files changed, 373 insertions(+) create mode 100644 tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.symbols create mode 100644 tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.types create mode 100644 tests/cases/compiler/contextualInnerCallFromConditionalContextualType2.ts diff --git a/tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.symbols b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.symbols new file mode 100644 index 0000000000000..c5c4f5b91398c --- /dev/null +++ b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.symbols @@ -0,0 +1,164 @@ +//// [tests/cases/compiler/contextualInnerCallFromConditionalContextualType2.ts] //// + +=== contextualInnerCallFromConditionalContextualType2.ts === +interface ActorImpl { +>ActorImpl : Symbol(ActorImpl, Decl(contextualInnerCallFromConditionalContextualType2.ts, 0, 0)) + + src: string; +>src : Symbol(ActorImpl.src, Decl(contextualInnerCallFromConditionalContextualType2.ts, 0, 21)) + + output: any; +>output : Symbol(ActorImpl.output, Decl(contextualInnerCallFromConditionalContextualType2.ts, 1, 14)) +} + +interface DoneInvokeEvent { +>DoneInvokeEvent : Symbol(DoneInvokeEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 3, 1)) +>TData : Symbol(TData, Decl(contextualInnerCallFromConditionalContextualType2.ts, 5, 26)) + + type: `done.invoke.${string}`; +>type : Symbol(DoneInvokeEvent.type, Decl(contextualInnerCallFromConditionalContextualType2.ts, 5, 34)) + + output: TData; +>output : Symbol(DoneInvokeEvent.output, Decl(contextualInnerCallFromConditionalContextualType2.ts, 6, 32)) +>TData : Symbol(TData, Decl(contextualInnerCallFromConditionalContextualType2.ts, 5, 26)) +} + +type AssignActionObject = { +>AssignActionObject : Symbol(AssignActionObject, Decl(contextualInnerCallFromConditionalContextualType2.ts, 8, 1)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 10, 24)) +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType2.ts, 10, 40)) + + type: "xstate.assign"; +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType2.ts, 10, 60)) + + ev: TEvent; +>ev : Symbol(ev, Decl(contextualInnerCallFromConditionalContextualType2.ts, 11, 24)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 10, 24)) + + (ev: TEvent): void; +>ev : Symbol(ev, Decl(contextualInnerCallFromConditionalContextualType2.ts, 13, 3)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 10, 24)) + +}; + +type ActionFunction = (ev: TEvent) => void; +>ActionFunction : Symbol(ActionFunction, Decl(contextualInnerCallFromConditionalContextualType2.ts, 14, 2)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 16, 20)) +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType2.ts, 16, 36)) +>ev : Symbol(ev, Decl(contextualInnerCallFromConditionalContextualType2.ts, 16, 56)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 16, 20)) + +declare function assign( +>assign : Symbol(assign, Decl(contextualInnerCallFromConditionalContextualType2.ts, 16, 76)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 18, 24)) +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType2.ts, 18, 40)) + + assigner: (ev: TEvent) => void +>assigner : Symbol(assigner, Decl(contextualInnerCallFromConditionalContextualType2.ts, 18, 57)) +>ev : Symbol(ev, Decl(contextualInnerCallFromConditionalContextualType2.ts, 19, 13)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 18, 24)) + +): AssignActionObject; +>AssignActionObject : Symbol(AssignActionObject, Decl(contextualInnerCallFromConditionalContextualType2.ts, 8, 1)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 18, 24)) + +type Action = +>Action : Symbol(Action, Decl(contextualInnerCallFromConditionalContextualType2.ts, 20, 30)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 22, 12)) +>type : Symbol(type, Decl(contextualInnerCallFromConditionalContextualType2.ts, 22, 28)) + + | AssignActionObject +>AssignActionObject : Symbol(AssignActionObject, Decl(contextualInnerCallFromConditionalContextualType2.ts, 8, 1)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 22, 12)) + + | ActionFunction; +>ActionFunction : Symbol(ActionFunction, Decl(contextualInnerCallFromConditionalContextualType2.ts, 14, 2)) +>TEvent : Symbol(TEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 22, 12)) + +declare function createMachine(config: { +>createMachine : Symbol(createMachine, Decl(contextualInnerCallFromConditionalContextualType2.ts, 24, 27)) +>TActors : Symbol(TActors, Decl(contextualInnerCallFromConditionalContextualType2.ts, 26, 31)) +>ActorImpl : Symbol(ActorImpl, Decl(contextualInnerCallFromConditionalContextualType2.ts, 0, 0)) +>config : Symbol(config, Decl(contextualInnerCallFromConditionalContextualType2.ts, 26, 58)) + + types: { +>types : Symbol(types, Decl(contextualInnerCallFromConditionalContextualType2.ts, 26, 67)) + + actors: TActors; +>actors : Symbol(actors, Decl(contextualInnerCallFromConditionalContextualType2.ts, 27, 10)) +>TActors : Symbol(TActors, Decl(contextualInnerCallFromConditionalContextualType2.ts, 26, 31)) + + }; + states: Record< +>states : Symbol(states, Decl(contextualInnerCallFromConditionalContextualType2.ts, 29, 4)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + string, + { + invoke: TActors extends { src: infer TSrc } +>invoke : Symbol(invoke, Decl(contextualInnerCallFromConditionalContextualType2.ts, 32, 5)) +>TActors : Symbol(TActors, Decl(contextualInnerCallFromConditionalContextualType2.ts, 26, 31)) +>src : Symbol(src, Decl(contextualInnerCallFromConditionalContextualType2.ts, 33, 31)) +>TSrc : Symbol(TSrc, Decl(contextualInnerCallFromConditionalContextualType2.ts, 33, 42)) + + ? { + src: TSrc; +>src : Symbol(src, Decl(contextualInnerCallFromConditionalContextualType2.ts, 34, 11)) +>TSrc : Symbol(TSrc, Decl(contextualInnerCallFromConditionalContextualType2.ts, 33, 42)) + + onDone: Action>; +>onDone : Symbol(onDone, Decl(contextualInnerCallFromConditionalContextualType2.ts, 35, 22)) +>Action : Symbol(Action, Decl(contextualInnerCallFromConditionalContextualType2.ts, 20, 30)) +>DoneInvokeEvent : Symbol(DoneInvokeEvent, Decl(contextualInnerCallFromConditionalContextualType2.ts, 3, 1)) +>TActors : Symbol(TActors, Decl(contextualInnerCallFromConditionalContextualType2.ts, 26, 31)) + } + : never; + } + >; +}): void; + +createMachine({ +>createMachine : Symbol(createMachine, Decl(contextualInnerCallFromConditionalContextualType2.ts, 24, 27)) + + types: { +>types : Symbol(types, Decl(contextualInnerCallFromConditionalContextualType2.ts, 43, 15)) + + actors: {} as { +>actors : Symbol(actors, Decl(contextualInnerCallFromConditionalContextualType2.ts, 44, 10)) + + src: "getRandomNumber"; +>src : Symbol(src, Decl(contextualInnerCallFromConditionalContextualType2.ts, 45, 19)) + + output: { result: number }; +>output : Symbol(output, Decl(contextualInnerCallFromConditionalContextualType2.ts, 46, 29)) +>result : Symbol(result, Decl(contextualInnerCallFromConditionalContextualType2.ts, 47, 15)) + + }, + }, + states: { +>states : Symbol(states, Decl(contextualInnerCallFromConditionalContextualType2.ts, 49, 4)) + + a: { +>a : Symbol(a, Decl(contextualInnerCallFromConditionalContextualType2.ts, 50, 11)) + + invoke: { +>invoke : Symbol(invoke, Decl(contextualInnerCallFromConditionalContextualType2.ts, 51, 8)) + + src: "getRandomNumber", +>src : Symbol(src, Decl(contextualInnerCallFromConditionalContextualType2.ts, 52, 15)) + + onDone: assign((event) => { +>onDone : Symbol(onDone, Decl(contextualInnerCallFromConditionalContextualType2.ts, 53, 31)) +>assign : Symbol(assign, Decl(contextualInnerCallFromConditionalContextualType2.ts, 16, 76)) +>event : Symbol(event, Decl(contextualInnerCallFromConditionalContextualType2.ts, 54, 24)) + + event; +>event : Symbol(event, Decl(contextualInnerCallFromConditionalContextualType2.ts, 54, 24)) + + // ^? + }), + }, + }, + }, +}); + diff --git a/tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.types b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.types new file mode 100644 index 0000000000000..3d408776319d4 --- /dev/null +++ b/tests/baselines/reference/contextualInnerCallFromConditionalContextualType2.types @@ -0,0 +1,144 @@ +//// [tests/cases/compiler/contextualInnerCallFromConditionalContextualType2.ts] //// + +=== contextualInnerCallFromConditionalContextualType2.ts === +interface ActorImpl { + src: string; +>src : string + + output: any; +>output : any +} + +interface DoneInvokeEvent { + type: `done.invoke.${string}`; +>type : `done.invoke.${string}` + + output: TData; +>output : TData +} + +type AssignActionObject = { +>AssignActionObject : AssignActionObject +>type : string + + type: "xstate.assign"; +>type : "xstate.assign" + + ev: TEvent; +>ev : TEvent + + (ev: TEvent): void; +>ev : TEvent + +}; + +type ActionFunction = (ev: TEvent) => void; +>ActionFunction : ActionFunction +>type : string +>ev : TEvent + +declare function assign( +>assign : (assigner: (ev: TEvent) => void) => AssignActionObject +>type : string + + assigner: (ev: TEvent) => void +>assigner : (ev: TEvent) => void +>ev : TEvent + +): AssignActionObject; + +type Action = +>Action : Action +>type : string + + | AssignActionObject + | ActionFunction; + +declare function createMachine(config: { +>createMachine : (config: { types: { actors: TActors;}; states: Record>; } : never; }>; }) => void +>config : { types: { actors: TActors;}; states: Record>; } : never; }>; } + + types: { +>types : { actors: TActors; } + + actors: TActors; +>actors : TActors + + }; + states: Record< +>states : Record>; } : never; }> + + string, + { + invoke: TActors extends { src: infer TSrc } +>invoke : TActors extends { src: infer TSrc; } ? { src: TSrc; onDone: Action>; } : never +>src : TSrc + + ? { + src: TSrc; +>src : TSrc + + onDone: Action>; +>onDone : Action> + } + : never; + } + >; +}): void; + +createMachine({ +>createMachine({ types: { actors: {} as { src: "getRandomNumber"; output: { result: number }; }, }, states: { a: { invoke: { src: "getRandomNumber", onDone: assign((event) => { event; // ^? }), }, }, },}) : void +>createMachine : (config: { types: { actors: TActors; }; states: Record>; } : never; }>; }) => void +>{ types: { actors: {} as { src: "getRandomNumber"; output: { result: number }; }, }, states: { a: { invoke: { src: "getRandomNumber", onDone: assign((event) => { event; // ^? }), }, }, },} : { types: { actors: { src: "getRandomNumber"; output: { result: number;}; }; }; states: { a: { invoke: { src: "getRandomNumber"; onDone: AssignActionObject>; }; }; }; } + + types: { +>types : { actors: { src: "getRandomNumber"; output: { result: number;}; }; } +>{ actors: {} as { src: "getRandomNumber"; output: { result: number }; }, } : { actors: { src: "getRandomNumber"; output: { result: number;}; }; } + + actors: {} as { +>actors : { src: "getRandomNumber"; output: { result: number;}; } +>{} as { src: "getRandomNumber"; output: { result: number }; } : { src: "getRandomNumber"; output: { result: number;}; } +>{} : {} + + src: "getRandomNumber"; +>src : "getRandomNumber" + + output: { result: number }; +>output : { result: number; } +>result : number + + }, + }, + states: { +>states : { a: { invoke: { src: "getRandomNumber"; onDone: AssignActionObject>; }; }; } +>{ a: { invoke: { src: "getRandomNumber", onDone: assign((event) => { event; // ^? }), }, }, } : { a: { invoke: { src: "getRandomNumber"; onDone: AssignActionObject>; }; }; } + + a: { +>a : { invoke: { src: "getRandomNumber"; onDone: AssignActionObject>; }; } +>{ invoke: { src: "getRandomNumber", onDone: assign((event) => { event; // ^? }), }, } : { invoke: { src: "getRandomNumber"; onDone: AssignActionObject>; }; } + + invoke: { +>invoke : { src: "getRandomNumber"; onDone: AssignActionObject>; } +>{ src: "getRandomNumber", onDone: assign((event) => { event; // ^? }), } : { src: "getRandomNumber"; onDone: AssignActionObject>; } + + src: "getRandomNumber", +>src : "getRandomNumber" +>"getRandomNumber" : "getRandomNumber" + + onDone: assign((event) => { +>onDone : AssignActionObject> +>assign((event) => { event; // ^? }) : AssignActionObject> +>assign : (assigner: (ev: TEvent) => void) => AssignActionObject +>(event) => { event; // ^? } : (event: DoneInvokeEvent<{ result: number; }>) => void +>event : DoneInvokeEvent<{ result: number; }> + + event; +>event : DoneInvokeEvent<{ result: number; }> + + // ^? + }), + }, + }, + }, +}); + diff --git a/tests/cases/compiler/contextualInnerCallFromConditionalContextualType2.ts b/tests/cases/compiler/contextualInnerCallFromConditionalContextualType2.ts new file mode 100644 index 0000000000000..88f6a27aa86af --- /dev/null +++ b/tests/cases/compiler/contextualInnerCallFromConditionalContextualType2.ts @@ -0,0 +1,65 @@ +// @strict: true +// @noEmit: true + +interface ActorImpl { + src: string; + output: any; +} + +interface DoneInvokeEvent { + type: `done.invoke.${string}`; + output: TData; +} + +type AssignActionObject = { + type: "xstate.assign"; + ev: TEvent; + (ev: TEvent): void; +}; + +type ActionFunction = (ev: TEvent) => void; + +declare function assign( + assigner: (ev: TEvent) => void +): AssignActionObject; + +type Action = + | AssignActionObject + | ActionFunction; + +declare function createMachine(config: { + types: { + actors: TActors; + }; + states: Record< + string, + { + invoke: TActors extends { src: infer TSrc } + ? { + src: TSrc; + onDone: Action>; + } + : never; + } + >; +}): void; + +createMachine({ + types: { + actors: {} as { + src: "getRandomNumber"; + output: { result: number }; + }, + }, + states: { + a: { + invoke: { + src: "getRandomNumber", + onDone: assign((event) => { + event; + // ^? + }), + }, + }, + }, +}); From e3f11a895c4d8ec4630027e313bb5aaa55ce21f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Thu, 11 Jan 2024 18:10:28 +0100 Subject: [PATCH 8/8] Go back to instantiating only conditional types --- src/compiler/checker.ts | 2 +- ...tualInnerCallFromIndexedAccessType.symbols | 108 ------------------ ...extualInnerCallFromIndexedAccessType.types | 92 --------------- ...appedTypeIntersectionConstraint.errors.txt | 11 +- ...erseMappedTypeIntersectionConstraint.types | 36 +++--- ...ontextualInnerCallFromIndexedAccessType.ts | 41 ------- 6 files changed, 25 insertions(+), 265 deletions(-) delete mode 100644 tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols delete mode 100644 tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types delete mode 100644 tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5b1cf22c29310..2948683e2066f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -30754,7 +30754,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // replaced with their constraints similar to the apparent type. if ( inferenceContext && - (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Simplifiable)) && + (contextFlags! & ContextFlags.Signature || maybeTypeOfKind(contextualType, TypeFlags.Conditional)) && some(inferenceContext.inferences, hasInferenceCandidatesOrDefault) ) { // For contextual signatures we incorporate all inferences made so far, e.g. from return diff --git a/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols b/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols deleted file mode 100644 index 62b8f23597550..0000000000000 --- a/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.symbols +++ /dev/null @@ -1,108 +0,0 @@ -//// [tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts] //// - -=== contextualInnerCallFromIndexedAccessType.ts === -interface EventObject { type: string; } ->EventObject : Symbol(EventObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 0)) ->type : Symbol(EventObject.type, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 23)) - -interface TypegenDisabled { "@@xstate/typegen": 0; } ->TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 39)) ->"@@xstate/typegen" : Symbol(TypegenDisabled["@@xstate/typegen"], Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 27)) - -interface TypegenEnabled { "@@xstate/typegen": 1; } ->TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 52)) ->"@@xstate/typegen" : Symbol(TypegenEnabled["@@xstate/typegen"], Decl(contextualInnerCallFromIndexedAccessType.ts, 2, 26)) - -type TypegenConstraint = TypegenEnabled | TypegenDisabled; ->TypegenConstraint : Symbol(TypegenConstraint, Decl(contextualInnerCallFromIndexedAccessType.ts, 2, 51)) ->TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 52)) ->TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 39)) - -interface ActionObject { ->ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) ->TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 6, 23)) ->EventObject : Symbol(EventObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 0)) - - type: string; ->type : Symbol(ActionObject.type, Decl(contextualInnerCallFromIndexedAccessType.ts, 6, 52)) - - _TE?: TEvent; ->_TE : Symbol(ActionObject._TE, Decl(contextualInnerCallFromIndexedAccessType.ts, 7, 15)) ->TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 6, 23)) -} - -declare function assign( ->assign : Symbol(assign, Decl(contextualInnerCallFromIndexedAccessType.ts, 9, 1)) ->TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 24)) ->EventObject : Symbol(EventObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 0)) - - assignment: (ev: TEvent) => void ->assignment : Symbol(assignment, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 52)) ->ev : Symbol(ev, Decl(contextualInnerCallFromIndexedAccessType.ts, 12, 15)) ->TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 24)) - -): ActionObject; ->ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) ->TEvent : Symbol(TEvent, Decl(contextualInnerCallFromIndexedAccessType.ts, 11, 24)) - -declare function createMachine< ->createMachine : Symbol(createMachine, Decl(contextualInnerCallFromIndexedAccessType.ts, 13, 24)) - - TTypesMeta extends TypegenConstraint = TypegenDisabled ->TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromIndexedAccessType.ts, 15, 31)) ->TypegenConstraint : Symbol(TypegenConstraint, Decl(contextualInnerCallFromIndexedAccessType.ts, 2, 51)) ->TypegenDisabled : Symbol(TypegenDisabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 0, 39)) - ->( - config: { ->config : Symbol(config, Decl(contextualInnerCallFromIndexedAccessType.ts, 17, 2)) - - types?: TTypesMeta; ->types : Symbol(types, Decl(contextualInnerCallFromIndexedAccessType.ts, 18, 11)) ->TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromIndexedAccessType.ts, 15, 31)) - - }, - action?: { ->action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 20, 4)) - - 1: { action: ActionObject<{ type: "WITH_TYPEGEN" }> }; ->1 : Symbol(1, Decl(contextualInnerCallFromIndexedAccessType.ts, 21, 12)) ->action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 8)) ->ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) ->type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 31)) - - 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> }; ->0 : Symbol(0, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 58)) ->action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 23, 8)) ->ActionObject : Symbol(ActionObject, Decl(contextualInnerCallFromIndexedAccessType.ts, 4, 58)) ->type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 23, 31)) - - }[TTypesMeta["@@xstate/typegen"]] ->TTypesMeta : Symbol(TTypesMeta, Decl(contextualInnerCallFromIndexedAccessType.ts, 15, 31)) - -): void; - -createMachine( ->createMachine : Symbol(createMachine, Decl(contextualInnerCallFromIndexedAccessType.ts, 13, 24)) - { - types: {} as TypegenEnabled, ->types : Symbol(types, Decl(contextualInnerCallFromIndexedAccessType.ts, 28, 3)) ->TypegenEnabled : Symbol(TypegenEnabled, Decl(contextualInnerCallFromIndexedAccessType.ts, 1, 52)) - - }, - { - action: assign((event) => { ->action : Symbol(action, Decl(contextualInnerCallFromIndexedAccessType.ts, 31, 3)) ->assign : Symbol(assign, Decl(contextualInnerCallFromIndexedAccessType.ts, 9, 1)) ->event : Symbol(event, Decl(contextualInnerCallFromIndexedAccessType.ts, 32, 20)) - - event.type // should be 'WITH_TYPEGEN' ->event.type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 31)) ->event : Symbol(event, Decl(contextualInnerCallFromIndexedAccessType.ts, 32, 20)) ->type : Symbol(type, Decl(contextualInnerCallFromIndexedAccessType.ts, 22, 31)) - - }), - } -); - - diff --git a/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types b/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types deleted file mode 100644 index 2ba2dfbb97937..0000000000000 --- a/tests/baselines/reference/contextualInnerCallFromIndexedAccessType.types +++ /dev/null @@ -1,92 +0,0 @@ -//// [tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts] //// - -=== contextualInnerCallFromIndexedAccessType.ts === -interface EventObject { type: string; } ->type : string - -interface TypegenDisabled { "@@xstate/typegen": 0; } ->"@@xstate/typegen" : 0 - -interface TypegenEnabled { "@@xstate/typegen": 1; } ->"@@xstate/typegen" : 1 - -type TypegenConstraint = TypegenEnabled | TypegenDisabled; ->TypegenConstraint : TypegenDisabled | TypegenEnabled - -interface ActionObject { - type: string; ->type : string - - _TE?: TEvent; ->_TE : TEvent | undefined -} - -declare function assign( ->assign : (assignment: (ev: TEvent) => void) => ActionObject - - assignment: (ev: TEvent) => void ->assignment : (ev: TEvent) => void ->ev : TEvent - -): ActionObject; - -declare function createMachine< ->createMachine : (config: { types?: TTypesMeta;}, action?: { 1: { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; }; 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>; };}[TTypesMeta["@@xstate/typegen"]]) => void - - TTypesMeta extends TypegenConstraint = TypegenDisabled ->( - config: { ->config : { types?: TTypesMeta | undefined; } - - types?: TTypesMeta; ->types : TTypesMeta | undefined - - }, - action?: { ->action : { 1: { action: ActionObject<{ type: "WITH_TYPEGEN"; }>;}; 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>;}; }[TTypesMeta["@@xstate/typegen"]] | undefined - - 1: { action: ActionObject<{ type: "WITH_TYPEGEN" }> }; ->1 : { action: ActionObject<{ type: "WITH_TYPEGEN";}>; } ->action : ActionObject<{ type: "WITH_TYPEGEN"; }> ->type : "WITH_TYPEGEN" - - 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> }; ->0 : { action: ActionObject<{ type: "WITHOUT_TYPEGEN";}>; } ->action : ActionObject<{ type: "WITHOUT_TYPEGEN"; }> ->type : "WITHOUT_TYPEGEN" - - }[TTypesMeta["@@xstate/typegen"]] -): void; - -createMachine( ->createMachine( { types: {} as TypegenEnabled, }, { action: assign((event) => { event.type // should be 'WITH_TYPEGEN' }), }) : void ->createMachine : (config: { types?: TTypesMeta | undefined; }, action?: { 1: { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; }; 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN"; }>; }; }[TTypesMeta["@@xstate/typegen"]] | undefined) => void - { ->{ types: {} as TypegenEnabled, } : { types: TypegenEnabled; } - - types: {} as TypegenEnabled, ->types : TypegenEnabled ->{} as TypegenEnabled : TypegenEnabled ->{} : {} - - }, - { ->{ action: assign((event) => { event.type // should be 'WITH_TYPEGEN' }), } : { action: ActionObject<{ type: "WITH_TYPEGEN"; }>; } - - action: assign((event) => { ->action : ActionObject<{ type: "WITH_TYPEGEN"; }> ->assign((event) => { event.type // should be 'WITH_TYPEGEN' }) : ActionObject<{ type: "WITH_TYPEGEN"; }> ->assign : (assignment: (ev: TEvent) => void) => ActionObject ->(event) => { event.type // should be 'WITH_TYPEGEN' } : (event: { type: "WITH_TYPEGEN"; }) => void ->event : { type: "WITH_TYPEGEN"; } - - event.type // should be 'WITH_TYPEGEN' ->event.type : "WITH_TYPEGEN" ->event : { type: "WITH_TYPEGEN"; } ->type : "WITH_TYPEGEN" - - }), - } -); - - diff --git a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.errors.txt b/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.errors.txt index 143a6e11a8275..ec7eab991b0ed 100644 --- a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.errors.txt +++ b/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.errors.txt @@ -1,5 +1,5 @@ -reverseMappedTypeIntersectionConstraint.ts(22,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: string; states: { a: { entry: string; }; }; }'. -reverseMappedTypeIntersectionConstraint.ts(32,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: string; states: { a: { entry: string; }; }; }'. +reverseMappedTypeIntersectionConstraint.ts(19,7): error TS2322: Type '"bar"' is not assignable to type '"foo"'. +reverseMappedTypeIntersectionConstraint.ts(32,3): error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: "foo"; states: { a: { entry: "foo"; }; }; }'. reverseMappedTypeIntersectionConstraint.ts(43,3): error TS2353: Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: "y"; }'. reverseMappedTypeIntersectionConstraint.ts(59,7): error TS2322: Type '{ [K in keyof T & keyof Stuff]: T[K]; }' is not assignable to type 'T'. '{ [K in keyof T & keyof Stuff]: T[K]; }' is assignable to the constraint of type 'T', but 'T' could be instantiated with a different subtype of constraint 'Stuff'. @@ -37,11 +37,12 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal states: { a: { entry: "bar", + ~~~~~ +!!! error TS2322: Type '"bar"' is not assignable to type '"foo"'. +!!! related TS6500 reverseMappedTypeIntersectionConstraint.ts:2:3: The expected type comes from property 'entry' which is declared here on type 'StateConfig<"foo">' }, }, extra: 12, - ~~~~~ -!!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: string; states: { a: { entry: string; }; }; }'. }); const inferredParams2 = createMachine({ @@ -53,7 +54,7 @@ reverseMappedTypeIntersectionConstraint.ts(171,3): error TS2353: Object literal }, extra: 12, ~~~~~ -!!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: string; states: { a: { entry: string; }; }; }'. +!!! error TS2353: Object literal may only specify known properties, and 'extra' does not exist in type '{ entry: "foo"; states: { a: { entry: "foo"; }; }; }'. }); diff --git a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.types b/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.types index 8b33fe04be863..43b568dd83d87 100644 --- a/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.types +++ b/tests/baselines/reference/reverseMappedTypeIntersectionConstraint.types @@ -29,25 +29,25 @@ declare function createMachine< >config : { [K in keyof TConfig & keyof StateConfig]: TConfig[K]; } const inferredParams1 = createMachine({ ->inferredParams1 : [string, { entry: string; states: { a: { entry: string; }; }; }] ->createMachine({ entry: "foo", states: { a: { entry: "bar", }, }, extra: 12,}) : [string, { entry: string; states: { a: { entry: string; }; }; }] +>inferredParams1 : ["foo", StateConfig<"foo">] +>createMachine({ entry: "foo", states: { a: { entry: "bar", }, }, extra: 12,}) : ["foo", StateConfig<"foo">] >createMachine : , TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string>(config: { [K in keyof TConfig & keyof StateConfig]: TConfig[K]; }) => [TAction, TConfig] ->{ entry: "foo", states: { a: { entry: "bar", }, }, extra: 12,} : { entry: string; states: { a: { entry: string; }; }; extra: number; } +>{ entry: "foo", states: { a: { entry: "bar", }, }, extra: 12,} : { entry: "foo"; states: { a: { entry: "bar"; }; }; extra: number; } entry: "foo", ->entry : string +>entry : "foo" >"foo" : "foo" states: { ->states : { a: { entry: string; }; } ->{ a: { entry: "bar", }, } : { a: { entry: string; }; } +>states : { a: { entry: "bar"; }; } +>{ a: { entry: "bar", }, } : { a: { entry: "bar"; }; } a: { ->a : { entry: string; } ->{ entry: "bar", } : { entry: string; } +>a : { entry: "bar"; } +>{ entry: "bar", } : { entry: "bar"; } entry: "bar", ->entry : string +>entry : "bar" >"bar" : "bar" }, @@ -59,25 +59,25 @@ const inferredParams1 = createMachine({ }); const inferredParams2 = createMachine({ ->inferredParams2 : [string, { entry: string; states: { a: { entry: string; }; }; }] ->createMachine({ entry: "foo", states: { a: { entry: "foo", }, }, extra: 12,}) : [string, { entry: string; states: { a: { entry: string; }; }; }] +>inferredParams2 : ["foo", { entry: "foo"; states: { a: { entry: "foo"; }; }; }] +>createMachine({ entry: "foo", states: { a: { entry: "foo", }, }, extra: 12,}) : ["foo", { entry: "foo"; states: { a: { entry: "foo"; }; }; }] >createMachine : , TAction extends string = TConfig["entry"] extends string ? TConfig["entry"] : string>(config: { [K in keyof TConfig & keyof StateConfig]: TConfig[K]; }) => [TAction, TConfig] ->{ entry: "foo", states: { a: { entry: "foo", }, }, extra: 12,} : { entry: string; states: { a: { entry: string; }; }; extra: number; } +>{ entry: "foo", states: { a: { entry: "foo", }, }, extra: 12,} : { entry: "foo"; states: { a: { entry: "foo"; }; }; extra: number; } entry: "foo", ->entry : string +>entry : "foo" >"foo" : "foo" states: { ->states : { a: { entry: string; }; } ->{ a: { entry: "foo", }, } : { a: { entry: string; }; } +>states : { a: { entry: "foo"; }; } +>{ a: { entry: "foo", }, } : { a: { entry: "foo"; }; } a: { ->a : { entry: string; } ->{ entry: "foo", } : { entry: string; } +>a : { entry: "foo"; } +>{ entry: "foo", } : { entry: "foo"; } entry: "foo", ->entry : string +>entry : "foo" >"foo" : "foo" }, diff --git a/tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts b/tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts deleted file mode 100644 index f8ff53a042b4a..0000000000000 --- a/tests/cases/compiler/contextualInnerCallFromIndexedAccessType.ts +++ /dev/null @@ -1,41 +0,0 @@ -// @strict: true -// @noEmit: true - -interface EventObject { type: string; } -interface TypegenDisabled { "@@xstate/typegen": 0; } -interface TypegenEnabled { "@@xstate/typegen": 1; } - -type TypegenConstraint = TypegenEnabled | TypegenDisabled; - -interface ActionObject { - type: string; - _TE?: TEvent; -} - -declare function assign( - assignment: (ev: TEvent) => void -): ActionObject; - -declare function createMachine< - TTypesMeta extends TypegenConstraint = TypegenDisabled ->( - config: { - types?: TTypesMeta; - }, - action?: { - 1: { action: ActionObject<{ type: "WITH_TYPEGEN" }> }; - 0: { action: ActionObject<{ type: "WITHOUT_TYPEGEN" }> }; - }[TTypesMeta["@@xstate/typegen"]] -): void; - -createMachine( - { - types: {} as TypegenEnabled, - }, - { - action: assign((event) => { - event.type // should be 'WITH_TYPEGEN' - }), - } -); -