From c0e99ae1cc9718f07c0b7c4afea7665bbb5f541c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 19 Aug 2024 12:20:55 +0200 Subject: [PATCH] add extra test cases --- ...rtyOfGenericFilteringMappedType.errors.txt | 55 ++++ ...opertyOfGenericFilteringMappedType.symbols | 21 ++ ...PropertyOfGenericFilteringMappedType.types | 41 +++ ...ctionObjectPropertyIntersection.errors.txt | 155 ++++++++++ ...FunctionObjectPropertyIntersection.symbols | 284 +++++++++++++----- ...peFunctionObjectPropertyIntersection.types | 215 ++++++++++++- ...ualPropertyOfGenericFilteringMappedType.ts | 12 + ...lTypeFunctionObjectPropertyIntersection.ts | 49 +++ 8 files changed, 747 insertions(+), 85 deletions(-) create mode 100644 tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.errors.txt create mode 100644 tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.errors.txt diff --git a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.errors.txt b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.errors.txt new file mode 100644 index 0000000000000..0c45d770b1dad --- /dev/null +++ b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.errors.txt @@ -0,0 +1,55 @@ +contextualPropertyOfGenericFilteringMappedType.ts(38,5): error TS2353: Object literal may only specify known properties, and 'foo' does not exist in type '{ bar: (value: string, prop: "bar") => void; }'. +contextualPropertyOfGenericFilteringMappedType.ts(38,11): error TS7006: Parameter 'value' implicitly has an 'any' type. +contextualPropertyOfGenericFilteringMappedType.ts(38,18): error TS7006: Parameter 'key' implicitly has an 'any' type. + + +==== contextualPropertyOfGenericFilteringMappedType.ts (3 errors) ==== + declare function f1( + data: T, + handlers: { [P in keyof T as P]: (value: T[P], prop: P) => void }, + ): void; + + f1( + { + foo: 0, + bar: "", + }, + { + foo: (value, key) => {}, + bar: (value, key) => {}, + }, + ); + + declare function f2( + data: T, + handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void }, + ): void; + + f2( + { + foo: 0, + bar: "", + }, + { + bar: (value, key) => {}, + }, + ); + + f2( + { + foo: 0, + bar: "", + }, + { + foo: (value, key) => { + ~~~ +!!! error TS2353: Object literal may only specify known properties, and 'foo' does not exist in type '{ bar: (value: string, prop: "bar") => void; }'. + ~~~~~ +!!! error TS7006: Parameter 'value' implicitly has an 'any' type. + ~~~ +!!! error TS7006: Parameter 'key' implicitly has an 'any' type. + // implicit `any`s + }, + }, + ); + \ No newline at end of file diff --git a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols index 5bcaba07ec255..a49b80fcfc9d9 100644 --- a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols +++ b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.symbols @@ -88,3 +88,24 @@ f2( }, ); +f2( +>f2 : Symbol(f2, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 14, 2)) + { + foo: 0, +>foo : Symbol(foo, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 32, 3)) + + bar: "", +>bar : Symbol(bar, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 33, 11)) + + }, + { + foo: (value, key) => { +>foo : Symbol(foo, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 36, 3)) +>value : Symbol(value, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 37, 10)) +>key : Symbol(key, Decl(contextualPropertyOfGenericFilteringMappedType.ts, 37, 16)) + + // implicit `any`s + }, + }, +); + diff --git a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types index b55c98f6f650f..dd7dd68b0f8c8 100644 --- a/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types +++ b/tests/baselines/reference/contextualPropertyOfGenericFilteringMappedType.types @@ -125,3 +125,44 @@ f2( }, ); +f2( +>f2( { foo: 0, bar: "", }, { foo: (value, key) => { // implicit `any`s }, },) : void +> : ^^^^ +>f2 : (data: T, handlers: { [P in keyof T as T[P] extends string ? P : never]: (value: T[P], prop: P) => void; }) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^ ^^ ^^^^^ + { +>{ foo: 0, bar: "", } : { foo: number; bar: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + foo: 0, +>foo : number +> : ^^^^^^ +>0 : 0 +> : ^ + + bar: "", +>bar : string +> : ^^^^^^ +>"" : "" +> : ^^ + + }, + { +>{ foo: (value, key) => { // implicit `any`s }, } : { foo: (value: any, key: any) => void; } +> : ^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^^^^ + + foo: (value, key) => { +>foo : (value: any, key: any) => void +> : ^ ^^^^^^^ ^^^^^^^^^^^^^^ +>(value, key) => { // implicit `any`s } : (value: any, key: any) => void +> : ^ ^^^^^^^ ^^^^^^^^^^^^^^ +>value : any +> : ^^^ +>key : any +> : ^^^ + + // implicit `any`s + }, + }, +); + diff --git a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.errors.txt b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.errors.txt new file mode 100644 index 0000000000000..c6927b2005ad0 --- /dev/null +++ b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.errors.txt @@ -0,0 +1,155 @@ +contextualTypeFunctionObjectPropertyIntersection.ts(84,5): error TS2353: Object literal may only specify known properties, and 'bar' does not exist in type '{ FOO?: Action<{ type: "FOO"; }> | undefined; } & { "*"?: Action<{ type: "FOO"; } | { type: "bar"; }> | undefined; }'. +contextualTypeFunctionObjectPropertyIntersection.ts(84,11): error TS7006: Parameter 'ev' implicitly has an 'any' type. + + +==== contextualTypeFunctionObjectPropertyIntersection.ts (2 errors) ==== + // repro from #48812 + + type Action = (ev: TEvent) => void; + + interface MachineConfig { + schema: { + events: TEvent; + }; + on?: { + [K in TEvent["type"]]?: Action; + } & { + "*"?: Action; + }; + } + + declare function createMachine( + config: MachineConfig + ): void; + + createMachine({ + schema: { + events: {} as { type: "FOO" } | { type: "BAR" }, + }, + on: { + FOO: (ev) => { + ev.type; // should be 'FOO' + }, + }, + }); + + createMachine({ + schema: { + events: {} as { type: "FOO" } | { type: "BAR" }, + }, + on: { + "*": (ev) => { + ev.type; // should be 'FOO' | 'BAR' + }, + }, + }); + + interface MachineConfig2 { + schema: { + events: TEvent; + }; + on?: { + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; + } & { + "*"?: Action; + }; + } + + declare function createMachine2( + config: MachineConfig2 + ): void; + + createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + FOO: (ev) => { + ev.type; // should be 'FOO' + }, + }, + }); + + createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + "*": (ev) => { + ev.type; // should be 'FOO' | 'bar' + }, + }, + }); + + createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + bar: (ev) => { + ~~~ +!!! error TS2353: Object literal may only specify known properties, and 'bar' does not exist in type '{ FOO?: Action<{ type: "FOO"; }> | undefined; } & { "*"?: Action<{ type: "FOO"; } | { type: "bar"; }> | undefined; }'. +!!! related TS6500 contextualTypeFunctionObjectPropertyIntersection.ts:46:3: The expected type comes from property 'on' which is declared here on type 'MachineConfig2<{ type: "FOO"; } | { type: "bar"; }>' + ~~ +!!! error TS7006: Parameter 'ev' implicitly has an 'any' type. + ev // any + }, + }, + }); + + // repro from #49307#issuecomment-1143103607 + + declare function createSlice( + reducers: { [K: string]: (state: string) => void } & { + [K in keyof T]: object; + } + ): void; + + createSlice({ + f(a) {}, + }); + + // repro from #49307#issuecomment-1196014488 + + type Validate = T & { [K in keyof T]: object } + declare function f any>>(s: S, x: Validate): void; + + f(0, { + foo: s => s + 1, + }) + + // repro from 49307#issuecomment-1195858950 + + type SliceCaseReducers = Record State | void>; + + type ValidateSliceCaseReducers> = ACR & { + [T in keyof ACR]: ACR[T] extends { + reducer(s: S, action?: infer A): any; + } + ? { + prepare(...a: never[]): Omit; + } + : {}; + }; + + declare function createSlice< + State, + CaseReducers extends SliceCaseReducers + >(options: { + initialState: State | (() => State); + reducers: ValidateSliceCaseReducers; + }): void; + + export const clientSlice = createSlice({ + initialState: { + username: "", + isLoggedIn: false, + userId: "", + avatar: "", + }, + reducers: { + onClientUserChanged(state) {}, + }, + }); + + \ No newline at end of file diff --git a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols index 57db492d04925..1a681fad41bf7 100644 --- a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols +++ b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.symbols @@ -103,7 +103,7 @@ createMachine({ >"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 34, 7)) >ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 35, 10)) - ev.type; // should be 'FOO' + ev.type; // should be 'FOO' | 'BAR' >ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 37)) >ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 35, 10)) >type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 32, 37)) @@ -112,159 +112,291 @@ createMachine({ }, }); +interface MachineConfig2 { +>MachineConfig2 : Symbol(MachineConfig2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 41)) + + schema: { +>schema : Symbol(MachineConfig2.schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 59)) + + events: TEvent; +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 42, 11)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) + + }; + on?: { +>on : Symbol(MachineConfig2.on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 44, 4)) + + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>Uppercase : Symbol(Uppercase, Decl(lib.es5.d.ts, --, --)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 94)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 46, 5)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) + + } & { + "*"?: Action; +>"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 47, 7)) +>Action : Symbol(Action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 0, 0)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 41, 25)) + + }; +} + +declare function createMachine2( +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 32)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 48)) + + config: MachineConfig2 +>config : Symbol(config, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 65)) +>MachineConfig2 : Symbol(MachineConfig2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3)) +>TEvent : Symbol(TEvent, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 52, 32)) + +): void; + +createMachine2({ +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 16)) + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 57, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 59, 4)) + + FOO: (ev) => { +>FOO : Symbol(FOO, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 60, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 61, 10)) + + ev.type; // should be 'FOO' +>ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 19)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 61, 10)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 19)) + + }, + }, +}); + +createMachine2({ +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 67, 16)) + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 68, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 70, 4)) + + "*": (ev) => { +>"*" : Symbol("*", Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 71, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 72, 10)) + + ev.type; // should be 'FOO' | 'bar' +>ev.type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 37)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 72, 10)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 19), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 69, 37)) + + }, + }, +}); + +createMachine2({ +>createMachine2 : Symbol(createMachine2, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 1)) + + schema: { +>schema : Symbol(schema, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 78, 16)) + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : Symbol(events, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 79, 11)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 80, 19)) +>type : Symbol(type, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 80, 37)) + + }, + on: { +>on : Symbol(on, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 81, 4)) + + bar: (ev) => { +>bar : Symbol(bar, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 82, 7)) +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 83, 10)) + + ev // any +>ev : Symbol(ev, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 83, 10)) + + }, + }, +}); + // repro from #49307#issuecomment-1143103607 declare function createSlice( ->createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 74, 2)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 43, 29)) +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 91, 29)) reducers: { [K: string]: (state: string) => void } & { ->reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 43, 32)) ->K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 44, 15)) ->state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 44, 28)) +>reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 91, 32)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 92, 15)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 92, 28)) [K in keyof T]: object; ->K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 45, 5)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 43, 29)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 93, 5)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 91, 29)) } ): void; createSlice({ ->createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 74, 2)) +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) f(a) {}, ->f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 49, 13)) ->a : Symbol(a, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 50, 4)) +>f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 97, 13)) +>a : Symbol(a, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 98, 4)) }); // repro from #49307#issuecomment-1196014488 type Validate = T & { [K in keyof T]: object } ->Validate : Symbol(Validate, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 51, 3)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 55, 14)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 55, 14)) ->K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 55, 26)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 55, 14)) +>Validate : Symbol(Validate, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 99, 3)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 14)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 14)) +>K : Symbol(K, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 26)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 14)) declare function f any>>(s: S, x: Validate): void; ->f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 55, 49)) ->S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 19)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 21)) +>f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 49)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 19)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 21)) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 48)) ->S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 19)) ->s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 67)) ->S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 19)) ->x : Symbol(x, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 72)) ->Validate : Symbol(Validate, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 51, 3)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 56, 21)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 48)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 19)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 67)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 19)) +>x : Symbol(x, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 72)) +>Validate : Symbol(Validate, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 99, 3)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 104, 21)) f(0, { ->f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 55, 49)) +>f : Symbol(f, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 103, 49)) foo: s => s + 1, ->foo : Symbol(foo, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 58, 6)) ->s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 59, 6)) ->s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 59, 6)) +>foo : Symbol(foo, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 106, 6)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 107, 6)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 107, 6)) }) // repro from 49307#issuecomment-1195858950 type SliceCaseReducers = Record State | void>; ->SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 60, 2)) ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 64, 23)) +>SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 108, 2)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 23)) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) ->state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 64, 48)) ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 64, 23)) ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 64, 23)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 48)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 23)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 23)) type ValidateSliceCaseReducers> = ACR & { ->ValidateSliceCaseReducers : Symbol(ValidateSliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 64, 79)) ->S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 66, 31)) ->ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 66, 33)) ->SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 60, 2)) ->S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 66, 31)) ->ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 66, 33)) +>ValidateSliceCaseReducers : Symbol(ValidateSliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 79)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 31)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) +>SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 108, 2)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 31)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) [T in keyof ACR]: ACR[T] extends { ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 67, 3)) ->ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 66, 33)) ->ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 66, 33)) ->T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 67, 3)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 115, 3)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) +>ACR : Symbol(ACR, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 33)) +>T : Symbol(T, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 115, 3)) reducer(s: S, action?: infer A): any; ->reducer : Symbol(reducer, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 67, 36)) ->s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 68, 12)) ->S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 66, 31)) ->action : Symbol(action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 68, 17)) ->A : Symbol(A, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 68, 32)) +>reducer : Symbol(reducer, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 115, 36)) +>s : Symbol(s, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 12)) +>S : Symbol(S, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 114, 31)) +>action : Symbol(action, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 17)) +>A : Symbol(A, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 32)) } ? { prepare(...a: never[]): Omit; ->prepare : Symbol(prepare, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 70, 7)) ->a : Symbol(a, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 71, 16)) +>prepare : Symbol(prepare, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 118, 7)) +>a : Symbol(a, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 119, 16)) >Omit : Symbol(Omit, Decl(lib.es5.d.ts, --, --)) ->A : Symbol(A, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 68, 32)) +>A : Symbol(A, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 116, 32)) } : {}; }; declare function createSlice< ->createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 74, 2)) +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) State, ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 76, 29)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) CaseReducers extends SliceCaseReducers ->CaseReducers : Symbol(CaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 77, 8)) ->SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 60, 2)) ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 76, 29)) +>CaseReducers : Symbol(CaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 125, 8)) +>SliceCaseReducers : Symbol(SliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 108, 2)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) >(options: { ->options : Symbol(options, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 79, 2)) +>options : Symbol(options, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 127, 2)) initialState: State | (() => State); ->initialState : Symbol(initialState, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 79, 12)) ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 76, 29)) ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 76, 29)) +>initialState : Symbol(initialState, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 127, 12)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) reducers: ValidateSliceCaseReducers; ->reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 80, 38)) ->ValidateSliceCaseReducers : Symbol(ValidateSliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 64, 79)) ->State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 76, 29)) ->CaseReducers : Symbol(CaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 77, 8)) +>reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 128, 38)) +>ValidateSliceCaseReducers : Symbol(ValidateSliceCaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 112, 79)) +>State : Symbol(State, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 124, 29)) +>CaseReducers : Symbol(CaseReducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 125, 8)) }): void; export const clientSlice = createSlice({ ->clientSlice : Symbol(clientSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 84, 12)) ->createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 39, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 74, 2)) +>clientSlice : Symbol(clientSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 132, 12)) +>createSlice : Symbol(createSlice, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 3), Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 122, 2)) initialState: { ->initialState : Symbol(initialState, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 84, 40)) +>initialState : Symbol(initialState, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 132, 40)) username: "", ->username : Symbol(username, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 85, 17)) +>username : Symbol(username, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 133, 17)) isLoggedIn: false, ->isLoggedIn : Symbol(isLoggedIn, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 86, 17)) +>isLoggedIn : Symbol(isLoggedIn, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 134, 17)) userId: "", ->userId : Symbol(userId, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 87, 22)) +>userId : Symbol(userId, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 135, 22)) avatar: "", ->avatar : Symbol(avatar, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 88, 15)) +>avatar : Symbol(avatar, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 136, 15)) }, reducers: { ->reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 90, 4)) +>reducers : Symbol(reducers, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 138, 4)) onClientUserChanged(state) {}, ->onClientUserChanged : Symbol(onClientUserChanged, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 91, 13)) ->state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 92, 24)) +>onClientUserChanged : Symbol(onClientUserChanged, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 139, 13)) +>state : Symbol(state, Decl(contextualTypeFunctionObjectPropertyIntersection.ts, 140, 24)) }, }); + diff --git a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types index 8f7412b5536e2..02d0173439a01 100644 --- a/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types +++ b/tests/baselines/reference/contextualTypeFunctionObjectPropertyIntersection.types @@ -106,12 +106,12 @@ createMachine({ }); createMachine({ ->createMachine({ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' }, },}) : void -> : ^^^^ +>createMachine({ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'BAR' }, },}) : void +> : ^^^^ >createMachine : (config: MachineConfig) => void > : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ ->{ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' }, },} : { schema: { events: { type: "FOO"; } | { type: "BAR"; }; }; on: { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; }; } -> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "BAR" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'BAR' }, },} : { schema: { events: { type: "FOO"; } | { type: "BAR"; }; }; on: { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ schema: { >schema : { events: { type: "FOO"; } | { type: "BAR"; }; } @@ -135,18 +135,18 @@ createMachine({ on: { >on : { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; } > : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ ->{ "*": (ev) => { ev.type; // should be 'FOO' }, } : { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; } -> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>{ "*": (ev) => { ev.type; // should be 'FOO' | 'BAR' }, } : { "*": (ev: { type: "FOO"; } | { type: "BAR"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ "*": (ev) => { >"*" : (ev: { type: "FOO"; } | { type: "BAR"; }) => void > : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ ->(ev) => { ev.type; // should be 'FOO' } : (ev: { type: "FOO"; } | { type: "BAR"; }) => void -> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +>(ev) => { ev.type; // should be 'FOO' | 'BAR' } : (ev: { type: "FOO"; } | { type: "BAR"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ >ev : { type: "FOO"; } | { type: "BAR"; } > : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ - ev.type; // should be 'FOO' + ev.type; // should be 'FOO' | 'BAR' >ev.type : "FOO" | "BAR" > : ^^^^^^^^^^^^^ >ev : { type: "FOO"; } | { type: "BAR"; } @@ -158,6 +158,202 @@ createMachine({ }, }); +interface MachineConfig2 { +>type : string +> : ^^^^^^ + + schema: { +>schema : { events: TEvent; } +> : ^^^^^^^^^^ ^^^ + + events: TEvent; +>events : TEvent +> : ^^^^^^ + + }; + on?: { +>on : ({ [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action | undefined; } & { "*"?: Action; }) | undefined +> : ^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^ + + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; +>type : K +> : ^ + + } & { + "*"?: Action; +>"*" : Action | undefined +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^ + + }; +} + +declare function createMachine2( +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>type : string +> : ^^^^^^ + + config: MachineConfig2 +>config : MachineConfig2 +> : ^^^^^^^^^^^^^^^^^^^^^^ + +): void; + +createMachine2({ +>createMachine2({ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { FOO: (ev) => { ev.type; // should be 'FOO' }, },}) : void +> : ^^^^ +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { FOO: (ev) => { ev.type; // should be 'FOO' }, },} : { schema: { events: { type: "FOO"; } | { type: "bar"; }; }; on: { FOO: (ev: { type: "FOO"; }) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "bar" }, } : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "bar" } : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "bar" +> : ^^^^^ + + }, + on: { +>on : { FOO: (ev: { type: "FOO"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>{ FOO: (ev) => { ev.type; // should be 'FOO' }, } : { FOO: (ev: { type: "FOO"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + FOO: (ev) => { +>FOO : (ev: { type: "FOO"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^ +>(ev) => { ev.type; // should be 'FOO' } : (ev: { type: "FOO"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^ +>ev : { type: "FOO"; } +> : ^^^^^^^^ ^^^ + + ev.type; // should be 'FOO' +>ev.type : "FOO" +> : ^^^^^ +>ev : { type: "FOO"; } +> : ^^^^^^^^ ^^^ +>type : "FOO" +> : ^^^^^ + + }, + }, +}); + +createMachine2({ +>createMachine2({ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'bar' }, },}) : void +> : ^^^^ +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { "*": (ev) => { ev.type; // should be 'FOO' | 'bar' }, },} : { schema: { events: { type: "FOO"; } | { type: "bar"; }; }; on: { "*": (ev: { type: "FOO"; } | { type: "bar"; }) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "bar" }, } : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "bar" } : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "bar" +> : ^^^^^ + + }, + on: { +>on : { "*": (ev: { type: "FOO"; } | { type: "bar"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>{ "*": (ev) => { ev.type; // should be 'FOO' | 'bar' }, } : { "*": (ev: { type: "FOO"; } | { type: "bar"; }) => void; } +> : ^^^^^^^^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + "*": (ev) => { +>"*" : (ev: { type: "FOO"; } | { type: "bar"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +>(ev) => { ev.type; // should be 'FOO' | 'bar' } : (ev: { type: "FOO"; } | { type: "bar"; }) => void +> : ^ ^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^ +>ev : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ + + ev.type; // should be 'FOO' | 'bar' +>ev.type : "FOO" | "bar" +> : ^^^^^^^^^^^^^ +>ev : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>type : "FOO" | "bar" +> : ^^^^^^^^^^^^^ + + }, + }, +}); + +createMachine2({ +>createMachine2({ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { bar: (ev) => { ev // any }, },}) : void +> : ^^^^ +>createMachine2 : (config: MachineConfig2) => void +> : ^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>{ schema: { events: {} as { type: "FOO" } | { type: "bar" }, }, on: { bar: (ev) => { ev // any }, },} : { schema: { events: { type: "FOO"; } | { type: "bar"; }; }; on: { bar: (ev: any) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + schema: { +>schema : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ +>{ events: {} as { type: "FOO" } | { type: "bar" }, } : { events: { type: "FOO"; } | { type: "bar"; }; } +> : ^^^^^^^^^^ ^^^ + + events: {} as { type: "FOO" } | { type: "bar" }, +>events : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} as { type: "FOO" } | { type: "bar" } : { type: "FOO"; } | { type: "bar"; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^ ^^^ +>{} : {} +> : ^^ +>type : "FOO" +> : ^^^^^ +>type : "bar" +> : ^^^^^ + + }, + on: { +>on : { bar: (ev: any) => void; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^ +>{ bar: (ev) => { ev // any }, } : { bar: (ev: any) => void; } +> : ^^^^^^^^ ^^^^^^^^^^^^^^^^^ + + bar: (ev) => { +>bar : (ev: any) => void +> : ^ ^^^^^^^^^^^^^^ +>(ev) => { ev // any } : (ev: any) => void +> : ^ ^^^^^^^^^^^^^^ +>ev : any +> : ^^^ + + ev // any +>ev : any +> : ^^^ + + }, + }, +}); + // repro from #49307#issuecomment-1143103607 declare function createSlice( @@ -341,3 +537,4 @@ export const clientSlice = createSlice({ }, }); + diff --git a/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts b/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts index 824a6d554344c..9b540f97206fd 100644 --- a/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts +++ b/tests/cases/compiler/contextualPropertyOfGenericFilteringMappedType.ts @@ -31,3 +31,15 @@ f2( bar: (value, key) => {}, }, ); + +f2( + { + foo: 0, + bar: "", + }, + { + foo: (value, key) => { + // implicit `any`s + }, + }, +); diff --git a/tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts b/tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts index b148284f50ba9..661595ea48862 100644 --- a/tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts +++ b/tests/cases/compiler/contextualTypeFunctionObjectPropertyIntersection.ts @@ -37,11 +37,59 @@ createMachine({ }, on: { "*": (ev) => { + ev.type; // should be 'FOO' | 'BAR' + }, + }, +}); + +interface MachineConfig2 { + schema: { + events: TEvent; + }; + on?: { + [K in TEvent["type"] as K extends Uppercase ? K : never]?: Action; + } & { + "*"?: Action; + }; +} + +declare function createMachine2( + config: MachineConfig2 +): void; + +createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + FOO: (ev) => { ev.type; // should be 'FOO' }, }, }); +createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + "*": (ev) => { + ev.type; // should be 'FOO' | 'bar' + }, + }, +}); + +createMachine2({ + schema: { + events: {} as { type: "FOO" } | { type: "bar" }, + }, + on: { + bar: (ev) => { + ev // any + }, + }, +}); + // repro from #49307#issuecomment-1143103607 declare function createSlice( @@ -96,3 +144,4 @@ export const clientSlice = createSlice({ onClientUserChanged(state) {}, }, }); +