diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8e5c03560db3e..901f3bce24b0f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -18932,7 +18932,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { type.flags & TypeFlags.Union ? getIntersectionType(map((type as UnionType).types, t => getIndexType(t, indexFlags))) : type.flags & TypeFlags.Intersection ? getUnionType(map((type as IntersectionType).types, t => getIndexType(t, indexFlags))) : getObjectFlags(type) & ObjectFlags.Mapped ? getIndexTypeForMappedType(type as MappedType, indexFlags) : - type === wildcardType ? wildcardType : + type === wildcardType || type === silentNeverType ? type : type.flags & TypeFlags.Unknown ? neverType : type.flags & (TypeFlags.Any | TypeFlags.Never) ? stringNumberSymbolType : getLiteralTypeFromProperties(type, (indexFlags & IndexFlags.NoIndexSignatures ? TypeFlags.StringLiteral : TypeFlags.StringLike) | (indexFlags & IndexFlags.StringsOnly ? 0 : TypeFlags.NumberLike | TypeFlags.ESSymbolLike), indexFlags === IndexFlags.None); diff --git a/tests/baselines/reference/noSilentNeverTypeLeak1.symbols b/tests/baselines/reference/noSilentNeverTypeLeak1.symbols new file mode 100644 index 0000000000000..f8d6b272b75bb --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak1.symbols @@ -0,0 +1,36 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak1.ts] //// + +=== noSilentNeverTypeLeak1.ts === +type Fn = (arg: T) => void; +>Fn : Symbol(Fn, Decl(noSilentNeverTypeLeak1.ts, 0, 0)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 0, 8)) +>arg : Symbol(arg, Decl(noSilentNeverTypeLeak1.ts, 0, 14)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 0, 8)) + +declare function fn1(): Fn; +>fn1 : Symbol(fn1, Decl(noSilentNeverTypeLeak1.ts, 0, 30)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 2, 21)) +>Fn : Symbol(Fn, Decl(noSilentNeverTypeLeak1.ts, 0, 0)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 2, 21)) + +declare function fn2( +>fn2 : Symbol(fn2, Decl(noSilentNeverTypeLeak1.ts, 2, 33)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 4, 21)) + + cb: Fn<{ +>cb : Symbol(cb, Decl(noSilentNeverTypeLeak1.ts, 4, 24)) +>Fn : Symbol(Fn, Decl(noSilentNeverTypeLeak1.ts, 0, 0)) + + [K in keyof T & string]: T[K]; +>K : Symbol(K, Decl(noSilentNeverTypeLeak1.ts, 6, 5)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 4, 21)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 4, 21)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak1.ts, 6, 5)) + + }>, +): void; + +fn2(fn1()); +>fn2 : Symbol(fn2, Decl(noSilentNeverTypeLeak1.ts, 2, 33)) +>fn1 : Symbol(fn1, Decl(noSilentNeverTypeLeak1.ts, 0, 30)) + diff --git a/tests/baselines/reference/noSilentNeverTypeLeak1.types b/tests/baselines/reference/noSilentNeverTypeLeak1.types new file mode 100644 index 0000000000000..35138ef7ac2ba --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak1.types @@ -0,0 +1,35 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak1.ts] //// + +=== noSilentNeverTypeLeak1.ts === +type Fn = (arg: T) => void; +>Fn : Fn +> : ^^^^^ +>arg : T +> : ^ + +declare function fn1(): Fn; +>fn1 : () => Fn +> : ^ ^^^^^^^ + +declare function fn2( +>fn2 : (cb: Fn<{ [K in keyof T & string]: T[K]; }>) => void +> : ^ ^^ ^^ ^^^^^ + + cb: Fn<{ +>cb : Fn<{ [K in keyof T & string]: T[K]; }> +> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof T & string]: T[K]; + }>, +): void; + +fn2(fn1()); +>fn2(fn1()) : void +> : ^^^^ +>fn2 : (cb: Fn<{ [K in keyof T & string]: T[K]; }>) => void +> : ^ ^^ ^^ ^^^^^ +>fn1() : Fn<{}> +> : ^^^^^^ +>fn1 : () => Fn +> : ^ ^^^^^^^ + diff --git a/tests/baselines/reference/noSilentNeverTypeLeak2.errors.txt b/tests/baselines/reference/noSilentNeverTypeLeak2.errors.txt new file mode 100644 index 0000000000000..9818c097906c1 --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak2.errors.txt @@ -0,0 +1,60 @@ +noSilentNeverTypeLeak2.ts(36,3): error TS2322: Type 'ActionFunction>' is not assignable to type 'ActionFunction>'. + Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. + Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. + Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'. + Types of property 'params' are incompatible. + Type 'unknown' is not assignable to type 'number'. + + +==== noSilentNeverTypeLeak2.ts (1 errors) ==== + type Values = T[keyof T]; + + interface ParameterizedObject { + type: string; + params?: unknown; + } + + type ActionFunction = { + (params: TParams): void; + _out_TAction?: TAction; + }; + + type ToParameterizedObject = Values<{ + [K in keyof TParameterizedMap & string]: { + type: K; + params: TParameterizedMap[K]; + }; + }>; + + declare function enqueueActions( + collect: (params: TParams) => void, + ): ActionFunction; + + declare function setup(actions: { + [K in keyof TActions]: ActionFunction< + TActions[K], + ToParameterizedObject + >; + }): void; + + setup({ + doStuff: enqueueActions((params: number) => {}), + }); + + setup({ + doStuff: enqueueActions((params: number) => {}), + ~~~~~~~ +!!! error TS2322: Type 'ActionFunction>' is not assignable to type 'ActionFunction>'. +!!! error TS2322: Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. +!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. +!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'. +!!! error TS2322: Types of property 'params' are incompatible. +!!! error TS2322: Type 'unknown' is not assignable to type 'number'. +!!! related TS6500 noSilentNeverTypeLeak2.ts:36:3: The expected type comes from property 'doStuff' which is declared here on type '{ doStuff: ActionFunction>; doOtherStuff: ActionFunction>; }' + doOtherStuff: (params: string) => {}, + }); + + setup({ + doStuff: enqueueActions((params: number) => {}), + doOtherStuff: (params) => {}, + }); \ No newline at end of file diff --git a/tests/baselines/reference/noSilentNeverTypeLeak2.symbols b/tests/baselines/reference/noSilentNeverTypeLeak2.symbols new file mode 100644 index 0000000000000..2d5e0d30ab850 --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak2.symbols @@ -0,0 +1,130 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak2.ts] //// + +=== noSilentNeverTypeLeak2.ts === +type Values = T[keyof T]; +>Values : Symbol(Values, Decl(noSilentNeverTypeLeak2.ts, 0, 0)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak2.ts, 0, 12)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak2.ts, 0, 12)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak2.ts, 0, 12)) + +interface ParameterizedObject { +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak2.ts, 0, 28)) + + type: string; +>type : Symbol(ParameterizedObject.type, Decl(noSilentNeverTypeLeak2.ts, 2, 31)) + + params?: unknown; +>params : Symbol(ParameterizedObject.params, Decl(noSilentNeverTypeLeak2.ts, 3, 15)) +} + +type ActionFunction = { +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak2.ts, 5, 1)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak2.ts, 7, 20)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak2.ts, 7, 28)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak2.ts, 0, 28)) + + (params: TParams): void; +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 8, 3)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak2.ts, 7, 20)) + + _out_TAction?: TAction; +>_out_TAction : Symbol(_out_TAction, Decl(noSilentNeverTypeLeak2.ts, 8, 26)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak2.ts, 7, 28)) + +}; + +type ToParameterizedObject = Values<{ +>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak2.ts, 10, 2)) +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak2.ts, 12, 27)) +>Values : Symbol(Values, Decl(noSilentNeverTypeLeak2.ts, 0, 0)) + + [K in keyof TParameterizedMap & string]: { +>K : Symbol(K, Decl(noSilentNeverTypeLeak2.ts, 13, 3)) +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak2.ts, 12, 27)) + + type: K; +>type : Symbol(type, Decl(noSilentNeverTypeLeak2.ts, 13, 44)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak2.ts, 13, 3)) + + params: TParameterizedMap[K]; +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 14, 12)) +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak2.ts, 12, 27)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak2.ts, 13, 3)) + + }; +}>; + +declare function enqueueActions( +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak2.ts, 17, 3)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak2.ts, 19, 32)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak2.ts, 19, 40)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak2.ts, 0, 28)) + + collect: (params: TParams) => void, +>collect : Symbol(collect, Decl(noSilentNeverTypeLeak2.ts, 19, 78)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 20, 12)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak2.ts, 19, 32)) + +): ActionFunction; +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak2.ts, 5, 1)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak2.ts, 19, 32)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak2.ts, 19, 40)) + +declare function setup(actions: { +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak2.ts, 21, 36)) +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak2.ts, 23, 23)) +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak2.ts, 23, 33)) + + [K in keyof TActions]: ActionFunction< +>K : Symbol(K, Decl(noSilentNeverTypeLeak2.ts, 24, 3)) +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak2.ts, 23, 23)) +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak2.ts, 5, 1)) + + TActions[K], +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak2.ts, 23, 23)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak2.ts, 24, 3)) + + ToParameterizedObject +>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak2.ts, 10, 2)) +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak2.ts, 23, 23)) + + >; +}): void; + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak2.ts, 21, 36)) + + doStuff: enqueueActions((params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak2.ts, 30, 7)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak2.ts, 17, 3)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 31, 27)) + +}); + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak2.ts, 21, 36)) + + doStuff: enqueueActions((params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak2.ts, 34, 7)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak2.ts, 17, 3)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 35, 27)) + + doOtherStuff: (params: string) => {}, +>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak2.ts, 35, 50)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 36, 17)) + +}); + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak2.ts, 21, 36)) + + doStuff: enqueueActions((params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak2.ts, 39, 7)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak2.ts, 17, 3)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 40, 27)) + + doOtherStuff: (params) => {}, +>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak2.ts, 40, 50)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak2.ts, 41, 17)) + +}); diff --git a/tests/baselines/reference/noSilentNeverTypeLeak2.types b/tests/baselines/reference/noSilentNeverTypeLeak2.types new file mode 100644 index 0000000000000..6ca10badace9f --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak2.types @@ -0,0 +1,152 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak2.ts] //// + +=== noSilentNeverTypeLeak2.ts === +type Values = T[keyof T]; +>Values : Values +> : ^^^^^^^^^ + +interface ParameterizedObject { + type: string; +>type : string +> : ^^^^^^ + + params?: unknown; +>params : unknown +> : ^^^^^^^ +} + +type ActionFunction = { +>ActionFunction : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + (params: TParams): void; +>params : TParams +> : ^^^^^^^ + + _out_TAction?: TAction; +>_out_TAction : TAction | undefined +> : ^^^^^^^^^^^^^^^^^^^ + +}; + +type ToParameterizedObject = Values<{ +>ToParameterizedObject : ToParameterizedObject +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof TParameterizedMap & string]: { + type: K; +>type : K +> : ^ + + params: TParameterizedMap[K]; +>params : TParameterizedMap[K] +> : ^^^^^^^^^^^^^^^^^^^^ + + }; +}>; + +declare function enqueueActions( +>enqueueActions : (collect: (params: TParams) => void) => ActionFunction +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^ + + collect: (params: TParams) => void, +>collect : (params: TParams) => void +> : ^ ^^ ^^^^^ +>params : TParams +> : ^^^^^^^ + +): ActionFunction; + +declare function setup(actions: { +>setup : (actions: { [K in keyof TActions]: ActionFunction>; }) => void +> : ^ ^^ ^^ ^^^^^ +>actions : { [K in keyof TActions]: ActionFunction>; } +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof TActions]: ActionFunction< + TActions[K], + ToParameterizedObject + >; +}): void; + +setup({ +>setup({ doStuff: enqueueActions((params: number) => {}),}) : void +> : ^^^^ +>setup : (actions: { [K in keyof TActions]: ActionFunction>; }) => void +> : ^ ^^ ^^ ^^^^^ +>{ doStuff: enqueueActions((params: number) => {}),} : { doStuff: ActionFunction; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + doStuff: enqueueActions((params: number) => {}), +>doStuff : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((params: number) => {}) : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: (params: TParams) => void) => ActionFunction +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>(params: number) => {} : (params: number) => void +> : ^ ^^ ^^^^^^^^^ +>params : number +> : ^^^^^^ + +}); + +setup({ +>setup({ doStuff: enqueueActions((params: number) => {}), doOtherStuff: (params: string) => {},}) : void +> : ^^^^ +>setup : (actions: { [K in keyof TActions]: ActionFunction>; }) => void +> : ^ ^^ ^^ ^^^^^ +>{ doStuff: enqueueActions((params: number) => {}), doOtherStuff: (params: string) => {},} : { doStuff: ActionFunction>; doOtherStuff: (params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ + + doStuff: enqueueActions((params: number) => {}), +>doStuff : ActionFunction> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((params: number) => {}) : ActionFunction> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: (params: TParams) => void) => ActionFunction +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>(params: number) => {} : (params: number) => void +> : ^ ^^ ^^^^^^^^^ +>params : number +> : ^^^^^^ + + doOtherStuff: (params: string) => {}, +>doOtherStuff : (params: string) => void +> : ^ ^^ ^^^^^^^^^ +>(params: string) => {} : (params: string) => void +> : ^ ^^ ^^^^^^^^^ +>params : string +> : ^^^^^^ + +}); + +setup({ +>setup({ doStuff: enqueueActions((params: number) => {}), doOtherStuff: (params) => {},}) : void +> : ^^^^ +>setup : (actions: { [K in keyof TActions]: ActionFunction>; }) => void +> : ^ ^^ ^^ ^^^^^ +>{ doStuff: enqueueActions((params: number) => {}), doOtherStuff: (params) => {},} : { doStuff: ActionFunction; doOtherStuff: (params: unknown) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^ + + doStuff: enqueueActions((params: number) => {}), +>doStuff : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((params: number) => {}) : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: (params: TParams) => void) => ActionFunction +> : ^ ^^ ^^^^^^^^^ ^^ ^^ ^^^^^ +>(params: number) => {} : (params: number) => void +> : ^ ^^ ^^^^^^^^^ +>params : number +> : ^^^^^^ + + doOtherStuff: (params) => {}, +>doOtherStuff : (params: unknown) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>(params) => {} : (params: unknown) => void +> : ^ ^^^^^^^^^^^^^^^^^^ +>params : unknown +> : ^^^^^^^ + +}); diff --git a/tests/baselines/reference/noSilentNeverTypeLeak3.errors.txt b/tests/baselines/reference/noSilentNeverTypeLeak3.errors.txt new file mode 100644 index 0000000000000..e7c0caa8e6878 --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak3.errors.txt @@ -0,0 +1,110 @@ +noSilentNeverTypeLeak3.ts(90,5): error TS2322: Type 'ActionFunction>' is not assignable to type 'ActionFunction>'. + Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. + Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. + Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'. + Types of property 'params' are incompatible. + Type 'unknown' is not assignable to type 'number'. + + +==== noSilentNeverTypeLeak3.ts (1 errors) ==== + // https://github.com/microsoft/TypeScript/issues/62824 + + type Values = T[keyof T]; + + type MachineContext = Record; + + interface ParameterizedObject { + type: string; + params?: unknown; + } + + type ActionFunction< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject, + > = { + (ctx: TContext, params: TParams): void; + _out_TAction?: TAction; + }; + + type ToParameterizedObject< + TParameterizedMap extends Record< + string, + ParameterizedObject["params"] | undefined + >, + > = Values<{ + [K in keyof TParameterizedMap & string]: { + type: K; + params: TParameterizedMap[K]; + }; + }>; + + type CollectActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + > = ( + { + context, + enqueue, + }: { + context: TContext; + enqueue: (action: () => void) => void; + }, + params: TParams, + ) => void; + + declare function enqueueActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject = ParameterizedObject, + >( + collect: CollectActions, + ): ActionFunction; + + declare function setup< + TContext extends MachineContext, + TActions extends Record< + string, + ParameterizedObject["params"] | undefined + > = {}, + >({ + types, + actions, + }: { + types?: { context?: TContext }; + actions?: { + [K in keyof TActions]: ActionFunction< + TContext, + TActions[K], + ToParameterizedObject + >; + }; + }): void; + + setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + }, + }); + + setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + doOtherStuff: (_, params: string) => {}, + }, + }); + + setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + ~~~~~~~ +!!! error TS2322: Type 'ActionFunction>' is not assignable to type 'ActionFunction>'. +!!! error TS2322: Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. +!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. +!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'. +!!! error TS2322: Types of property 'params' are incompatible. +!!! error TS2322: Type 'unknown' is not assignable to type 'number'. + doOtherStuff: (_: any, params: string) => {}, + }, + }); + \ No newline at end of file diff --git a/tests/baselines/reference/noSilentNeverTypeLeak3.symbols b/tests/baselines/reference/noSilentNeverTypeLeak3.symbols new file mode 100644 index 0000000000000..a9bd18dbb9c80 --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak3.symbols @@ -0,0 +1,255 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak3.ts] //// + +=== noSilentNeverTypeLeak3.ts === +// https://github.com/microsoft/TypeScript/issues/62824 + +type Values = T[keyof T]; +>Values : Symbol(Values, Decl(noSilentNeverTypeLeak3.ts, 0, 0)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak3.ts, 2, 12)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak3.ts, 2, 12)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak3.ts, 2, 12)) + +type MachineContext = Record; +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak3.ts, 2, 28)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + +interface ParameterizedObject { +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + + type: string; +>type : Symbol(ParameterizedObject.type, Decl(noSilentNeverTypeLeak3.ts, 6, 31)) + + params?: unknown; +>params : Symbol(ParameterizedObject.params, Decl(noSilentNeverTypeLeak3.ts, 7, 15)) +} + +type ActionFunction< +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak3.ts, 9, 1)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 11, 20)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak3.ts, 2, 28)) + + TParams extends ParameterizedObject["params"] | undefined, +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak3.ts, 12, 34)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + + TAction extends ParameterizedObject, +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak3.ts, 13, 60)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + +> = { + (ctx: TContext, params: TParams): void; +>ctx : Symbol(ctx, Decl(noSilentNeverTypeLeak3.ts, 16, 3)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 11, 20)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 16, 17)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak3.ts, 12, 34)) + + _out_TAction?: TAction; +>_out_TAction : Symbol(_out_TAction, Decl(noSilentNeverTypeLeak3.ts, 16, 41)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak3.ts, 13, 60)) + +}; + +type ToParameterizedObject< +>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 18, 2)) + + TParameterizedMap extends Record< +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak3.ts, 20, 27)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + string, + ParameterizedObject["params"] | undefined +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + + >, +> = Values<{ +>Values : Symbol(Values, Decl(noSilentNeverTypeLeak3.ts, 0, 0)) + + [K in keyof TParameterizedMap & string]: { +>K : Symbol(K, Decl(noSilentNeverTypeLeak3.ts, 26, 3)) +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak3.ts, 20, 27)) + + type: K; +>type : Symbol(type, Decl(noSilentNeverTypeLeak3.ts, 26, 44)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak3.ts, 26, 3)) + + params: TParameterizedMap[K]; +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 27, 12)) +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak3.ts, 20, 27)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak3.ts, 26, 3)) + + }; +}>; + +type CollectActions< +>CollectActions : Symbol(CollectActions, Decl(noSilentNeverTypeLeak3.ts, 30, 3)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 32, 20)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak3.ts, 2, 28)) + + TParams extends ParameterizedObject["params"] | undefined, +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak3.ts, 33, 34)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + +> = ( + { + context, +>context : Symbol(context, Decl(noSilentNeverTypeLeak3.ts, 36, 3)) + + enqueue, +>enqueue : Symbol(enqueue, Decl(noSilentNeverTypeLeak3.ts, 37, 12)) + + }: { + context: TContext; +>context : Symbol(context, Decl(noSilentNeverTypeLeak3.ts, 39, 6)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 32, 20)) + + enqueue: (action: () => void) => void; +>enqueue : Symbol(enqueue, Decl(noSilentNeverTypeLeak3.ts, 40, 22)) +>action : Symbol(action, Decl(noSilentNeverTypeLeak3.ts, 41, 14)) + + }, + params: TParams, +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 42, 4)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak3.ts, 33, 34)) + +) => void; + +declare function enqueueActions< +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak3.ts, 44, 10)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 46, 32)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak3.ts, 2, 28)) + + TParams extends ParameterizedObject["params"] | undefined, +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak3.ts, 47, 34)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + + TAction extends ParameterizedObject = ParameterizedObject, +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak3.ts, 48, 60)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + +>( + collect: CollectActions, +>collect : Symbol(collect, Decl(noSilentNeverTypeLeak3.ts, 50, 2)) +>CollectActions : Symbol(CollectActions, Decl(noSilentNeverTypeLeak3.ts, 30, 3)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 46, 32)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak3.ts, 47, 34)) + +): ActionFunction; +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak3.ts, 9, 1)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 46, 32)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak3.ts, 47, 34)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak3.ts, 48, 60)) + +declare function setup< +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak3.ts, 52, 46)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 54, 23)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak3.ts, 2, 28)) + + TActions extends Record< +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak3.ts, 55, 34)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + string, + ParameterizedObject["params"] | undefined +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 4, 42)) + + > = {}, +>({ + types, +>types : Symbol(types, Decl(noSilentNeverTypeLeak3.ts, 60, 3)) + + actions, +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak3.ts, 61, 8)) + +}: { + types?: { context?: TContext }; +>types : Symbol(types, Decl(noSilentNeverTypeLeak3.ts, 63, 4)) +>context : Symbol(context, Decl(noSilentNeverTypeLeak3.ts, 64, 11)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 54, 23)) + + actions?: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak3.ts, 64, 33)) + + [K in keyof TActions]: ActionFunction< +>K : Symbol(K, Decl(noSilentNeverTypeLeak3.ts, 66, 5)) +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak3.ts, 55, 34)) +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak3.ts, 9, 1)) + + TContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak3.ts, 54, 23)) + + TActions[K], +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak3.ts, 55, 34)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak3.ts, 66, 5)) + + ToParameterizedObject +>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak3.ts, 18, 2)) +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak3.ts, 55, 34)) + + >; + }; +}): void; + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak3.ts, 52, 46)) + + actions: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak3.ts, 74, 7)) + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak3.ts, 75, 12)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak3.ts, 44, 10)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak3.ts, 76, 29)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 76, 31)) + + }, +}); + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak3.ts, 52, 46)) + + actions: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak3.ts, 80, 7)) + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak3.ts, 81, 12)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak3.ts, 44, 10)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak3.ts, 82, 29)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 82, 31)) + + doOtherStuff: (_, params: string) => {}, +>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak3.ts, 82, 55)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak3.ts, 83, 19)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 83, 21)) + + }, +}); + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak3.ts, 52, 46)) + + actions: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak3.ts, 87, 7)) + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak3.ts, 88, 12)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak3.ts, 44, 10)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak3.ts, 89, 29)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 89, 31)) + + doOtherStuff: (_: any, params: string) => {}, +>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak3.ts, 89, 55)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak3.ts, 90, 19)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak3.ts, 90, 26)) + + }, +}); + diff --git a/tests/baselines/reference/noSilentNeverTypeLeak3.types b/tests/baselines/reference/noSilentNeverTypeLeak3.types new file mode 100644 index 0000000000000..3acae103e33fc --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak3.types @@ -0,0 +1,262 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak3.ts] //// + +=== noSilentNeverTypeLeak3.ts === +// https://github.com/microsoft/TypeScript/issues/62824 + +type Values = T[keyof T]; +>Values : Values +> : ^^^^^^^^^ + +type MachineContext = Record; +>MachineContext : MachineContext +> : ^^^^^^^^^^^^^^ + +interface ParameterizedObject { + type: string; +>type : string +> : ^^^^^^ + + params?: unknown; +>params : unknown +> : ^^^^^^^ +} + +type ActionFunction< +>ActionFunction : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject, +> = { + (ctx: TContext, params: TParams): void; +>ctx : TContext +> : ^^^^^^^^ +>params : TParams +> : ^^^^^^^ + + _out_TAction?: TAction; +>_out_TAction : TAction | undefined +> : ^^^^^^^^^^^^^^^^^^^ + +}; + +type ToParameterizedObject< +>ToParameterizedObject : ToParameterizedObject +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + TParameterizedMap extends Record< + string, + ParameterizedObject["params"] | undefined + >, +> = Values<{ + [K in keyof TParameterizedMap & string]: { + type: K; +>type : K +> : ^ + + params: TParameterizedMap[K]; +>params : TParameterizedMap[K] +> : ^^^^^^^^^^^^^^^^^^^^ + + }; +}>; + +type CollectActions< +>CollectActions : CollectActions +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, +> = ( + { + context, +>context : TContext +> : ^^^^^^^^ + + enqueue, +>enqueue : (action: () => void) => void +> : ^ ^^ ^^^^^ + + }: { + context: TContext; +>context : TContext +> : ^^^^^^^^ + + enqueue: (action: () => void) => void; +>enqueue : (action: () => void) => void +> : ^ ^^ ^^^^^ +>action : () => void +> : ^^^^^^ + + }, + params: TParams, +>params : TParams +> : ^^^^^^^ + +) => void; + +declare function enqueueActions< +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ + + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject = ParameterizedObject, +>( + collect: CollectActions, +>collect : CollectActions +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +): ActionFunction; + +declare function setup< +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ + + TContext extends MachineContext, + TActions extends Record< + string, + ParameterizedObject["params"] | undefined + > = {}, +>({ + types, +>types : { context?: TContext; } | undefined +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + actions, +>actions : { [K in keyof TActions]: ActionFunction>; } | undefined +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +}: { + types?: { context?: TContext }; +>types : { context?: TContext; } | undefined +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>context : TContext | undefined +> : ^^^^^^^^^^^^^^^^^^^^ + + actions?: { +>actions : { [K in keyof TActions]: ActionFunction>; } | undefined +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof TActions]: ActionFunction< + TContext, + TActions[K], + ToParameterizedObject + >; + }; +}): void; + +setup({ +>setup({ actions: { doStuff: enqueueActions((_, params: number) => {}), },}) : void +> : ^^^^ +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ +>{ actions: { doStuff: enqueueActions((_, params: number) => {}), },} : { actions: { doStuff: ActionFunction; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + actions: { +>actions : { doStuff: ActionFunction; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ doStuff: enqueueActions((_, params: number) => {}), } : { doStuff: ActionFunction; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((_, params: number) => {}) : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ +>(_, params: number) => {} : (_: { context: MachineContext; enqueue: (action: () => void) => void; }, params: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^ ^^^^^^^^^ +>_ : { context: MachineContext; enqueue: (action: () => void) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>params : number +> : ^^^^^^ + + }, +}); + +setup({ +>setup({ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_, params: string) => {}, },}) : void +> : ^^^^ +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ +>{ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_, params: string) => {}, },} : { actions: { doStuff: ActionFunction; doOtherStuff: (_: MachineContext, params: string) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^ + + actions: { +>actions : { doStuff: ActionFunction; doOtherStuff: (_: MachineContext, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ +>{ doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_, params: string) => {}, } : { doStuff: ActionFunction; doOtherStuff: (_: MachineContext, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((_, params: number) => {}) : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ +>(_, params: number) => {} : (_: { context: MachineContext; enqueue: (action: () => void) => void; }, params: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^ ^^^^^^^^^ +>_ : { context: MachineContext; enqueue: (action: () => void) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>params : number +> : ^^^^^^ + + doOtherStuff: (_, params: string) => {}, +>doOtherStuff : (_: MachineContext, params: string) => void +> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ +>(_, params: string) => {} : (_: MachineContext, params: string) => void +> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ +>_ : MachineContext +> : ^^^^^^^^^^^^^^ +>params : string +> : ^^^^^^ + + }, +}); + +setup({ +>setup({ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_: any, params: string) => {}, },}) : void +> : ^^^^ +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ +>{ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_: any, params: string) => {}, },} : { actions: { doStuff: ActionFunction>; doOtherStuff: (_: any, params: string) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^ + + actions: { +>actions : { doStuff: ActionFunction>; doOtherStuff: (_: any, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^ +>{ doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_: any, params: string) => {}, } : { doStuff: ActionFunction>; doOtherStuff: (_: any, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^ + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : ActionFunction> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((_, params: number) => {}) : ActionFunction> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ +>(_, params: number) => {} : (_: { context: MachineContext; enqueue: (action: () => void) => void; }, params: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^ ^^^^^^^^^ +>_ : { context: MachineContext; enqueue: (action: () => void) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>params : number +> : ^^^^^^ + + doOtherStuff: (_: any, params: string) => {}, +>doOtherStuff : (_: any, params: string) => void +> : ^ ^^ ^^ ^^ ^^^^^^^^^ +>(_: any, params: string) => {} : (_: any, params: string) => void +> : ^ ^^ ^^ ^^ ^^^^^^^^^ +>_ : any +> : ^^^ +>params : string +> : ^^^^^^ + + }, +}); + diff --git a/tests/baselines/reference/noSilentNeverTypeLeak4.errors.txt b/tests/baselines/reference/noSilentNeverTypeLeak4.errors.txt new file mode 100644 index 0000000000000..8d7fc3381d346 --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak4.errors.txt @@ -0,0 +1,128 @@ +noSilentNeverTypeLeak4.ts(75,5): error TS2322: Type 'ActionFunction' is not assignable to type 'ActionFunction'. + Type 'ParameterizedObject' is not assignable to type '{ type: "doStuff"; params: number; }'. + Types of property 'type' are incompatible. + Type 'string' is not assignable to type '"doStuff"'. +noSilentNeverTypeLeak4.ts(81,5): error TS2322: Type 'ActionFunction' is not assignable to type 'ActionFunction>'. + Type 'ParameterizedObject' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. + Type 'ParameterizedObject' is not assignable to type '{ type: "doOtherStuff"; params: string; }'. + Types of property 'type' are incompatible. + Type 'string' is not assignable to type '"doOtherStuff"'. +noSilentNeverTypeLeak4.ts(88,5): error TS2322: Type 'ActionFunction>' is not assignable to type 'ActionFunction>'. + Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. + Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. + Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'. + Types of property 'params' are incompatible. + Type 'unknown' is not assignable to type 'number'. + + +==== noSilentNeverTypeLeak4.ts (3 errors) ==== + type Values = T[keyof T]; + + type MachineContext = Record; + + interface ParameterizedObject { + type: string; + params?: unknown; + } + + type ActionFunction< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject, + > = { + (ctx: TContext, params: TParams): void; + _out_TAction?: TAction; + }; + + type ToParameterizedObject< + TParameterizedMap extends Record< + string, + ParameterizedObject["params"] | undefined + >, + > = Values<{ + [K in keyof TParameterizedMap as K & string]: { + type: K & string; + params: TParameterizedMap[K]; + }; + }>; + + type CollectActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + > = ( + { + context, + enqueue, + }: { + context: TContext; + enqueue: (action: () => void) => void; + }, + params: TParams, + ) => void; + + declare function enqueueActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject = ParameterizedObject, + >( + collect: CollectActions, + ): ActionFunction; + + declare function setup< + TContext extends MachineContext, + TActions extends Record< + string, + ParameterizedObject["params"] | undefined + > = {}, + >({ + types, + actions, + }: { + types?: { context?: TContext }; + actions?: { + [K in keyof TActions]: ActionFunction< + TContext, + TActions[K], + ToParameterizedObject + >; + }; + }): void; + + setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + ~~~~~~~ +!!! error TS2322: Type 'ActionFunction' is not assignable to type 'ActionFunction'. +!!! error TS2322: Type 'ParameterizedObject' is not assignable to type '{ type: "doStuff"; params: number; }'. +!!! error TS2322: Types of property 'type' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"doStuff"'. + }, + }); + + setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + ~~~~~~~ +!!! error TS2322: Type 'ActionFunction' is not assignable to type 'ActionFunction>'. +!!! error TS2322: Type 'ParameterizedObject' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. +!!! error TS2322: Type 'ParameterizedObject' is not assignable to type '{ type: "doOtherStuff"; params: string; }'. +!!! error TS2322: Types of property 'type' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type '"doOtherStuff"'. + doOtherStuff: (_, params: string) => {}, + }, + }); + + setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + ~~~~~~~ +!!! error TS2322: Type 'ActionFunction>' is not assignable to type 'ActionFunction>'. +!!! error TS2322: Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. +!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'. +!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'. +!!! error TS2322: Types of property 'params' are incompatible. +!!! error TS2322: Type 'unknown' is not assignable to type 'number'. + doOtherStuff: (_: any, params: string) => {}, + }, + }); + \ No newline at end of file diff --git a/tests/baselines/reference/noSilentNeverTypeLeak4.symbols b/tests/baselines/reference/noSilentNeverTypeLeak4.symbols new file mode 100644 index 0000000000000..68992120f5883 --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak4.symbols @@ -0,0 +1,254 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak4.ts] //// + +=== noSilentNeverTypeLeak4.ts === +type Values = T[keyof T]; +>Values : Symbol(Values, Decl(noSilentNeverTypeLeak4.ts, 0, 0)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak4.ts, 0, 12)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak4.ts, 0, 12)) +>T : Symbol(T, Decl(noSilentNeverTypeLeak4.ts, 0, 12)) + +type MachineContext = Record; +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak4.ts, 0, 28)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + +interface ParameterizedObject { +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + + type: string; +>type : Symbol(ParameterizedObject.type, Decl(noSilentNeverTypeLeak4.ts, 4, 31)) + + params?: unknown; +>params : Symbol(ParameterizedObject.params, Decl(noSilentNeverTypeLeak4.ts, 5, 15)) +} + +type ActionFunction< +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak4.ts, 7, 1)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 9, 20)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak4.ts, 0, 28)) + + TParams extends ParameterizedObject["params"] | undefined, +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak4.ts, 10, 34)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + + TAction extends ParameterizedObject, +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak4.ts, 11, 60)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + +> = { + (ctx: TContext, params: TParams): void; +>ctx : Symbol(ctx, Decl(noSilentNeverTypeLeak4.ts, 14, 3)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 9, 20)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 14, 17)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak4.ts, 10, 34)) + + _out_TAction?: TAction; +>_out_TAction : Symbol(_out_TAction, Decl(noSilentNeverTypeLeak4.ts, 14, 41)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak4.ts, 11, 60)) + +}; + +type ToParameterizedObject< +>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 16, 2)) + + TParameterizedMap extends Record< +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak4.ts, 18, 27)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + string, + ParameterizedObject["params"] | undefined +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + + >, +> = Values<{ +>Values : Symbol(Values, Decl(noSilentNeverTypeLeak4.ts, 0, 0)) + + [K in keyof TParameterizedMap as K & string]: { +>K : Symbol(K, Decl(noSilentNeverTypeLeak4.ts, 24, 3)) +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak4.ts, 18, 27)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak4.ts, 24, 3)) + + type: K & string; +>type : Symbol(type, Decl(noSilentNeverTypeLeak4.ts, 24, 49)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak4.ts, 24, 3)) + + params: TParameterizedMap[K]; +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 25, 21)) +>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak4.ts, 18, 27)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak4.ts, 24, 3)) + + }; +}>; + +type CollectActions< +>CollectActions : Symbol(CollectActions, Decl(noSilentNeverTypeLeak4.ts, 28, 3)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 30, 20)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak4.ts, 0, 28)) + + TParams extends ParameterizedObject["params"] | undefined, +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak4.ts, 31, 34)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + +> = ( + { + context, +>context : Symbol(context, Decl(noSilentNeverTypeLeak4.ts, 34, 3)) + + enqueue, +>enqueue : Symbol(enqueue, Decl(noSilentNeverTypeLeak4.ts, 35, 12)) + + }: { + context: TContext; +>context : Symbol(context, Decl(noSilentNeverTypeLeak4.ts, 37, 6)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 30, 20)) + + enqueue: (action: () => void) => void; +>enqueue : Symbol(enqueue, Decl(noSilentNeverTypeLeak4.ts, 38, 22)) +>action : Symbol(action, Decl(noSilentNeverTypeLeak4.ts, 39, 14)) + + }, + params: TParams, +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 40, 4)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak4.ts, 31, 34)) + +) => void; + +declare function enqueueActions< +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak4.ts, 42, 10)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 44, 32)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak4.ts, 0, 28)) + + TParams extends ParameterizedObject["params"] | undefined, +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak4.ts, 45, 34)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + + TAction extends ParameterizedObject = ParameterizedObject, +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak4.ts, 46, 60)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + +>( + collect: CollectActions, +>collect : Symbol(collect, Decl(noSilentNeverTypeLeak4.ts, 48, 2)) +>CollectActions : Symbol(CollectActions, Decl(noSilentNeverTypeLeak4.ts, 28, 3)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 44, 32)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak4.ts, 45, 34)) + +): ActionFunction; +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak4.ts, 7, 1)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 44, 32)) +>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak4.ts, 45, 34)) +>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak4.ts, 46, 60)) + +declare function setup< +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak4.ts, 50, 46)) + + TContext extends MachineContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 52, 23)) +>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak4.ts, 0, 28)) + + TActions extends Record< +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak4.ts, 53, 34)) +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) + + string, + ParameterizedObject["params"] | undefined +>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 2, 42)) + + > = {}, +>({ + types, +>types : Symbol(types, Decl(noSilentNeverTypeLeak4.ts, 58, 3)) + + actions, +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak4.ts, 59, 8)) + +}: { + types?: { context?: TContext }; +>types : Symbol(types, Decl(noSilentNeverTypeLeak4.ts, 61, 4)) +>context : Symbol(context, Decl(noSilentNeverTypeLeak4.ts, 62, 11)) +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 52, 23)) + + actions?: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak4.ts, 62, 33)) + + [K in keyof TActions]: ActionFunction< +>K : Symbol(K, Decl(noSilentNeverTypeLeak4.ts, 64, 5)) +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak4.ts, 53, 34)) +>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak4.ts, 7, 1)) + + TContext, +>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak4.ts, 52, 23)) + + TActions[K], +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak4.ts, 53, 34)) +>K : Symbol(K, Decl(noSilentNeverTypeLeak4.ts, 64, 5)) + + ToParameterizedObject +>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak4.ts, 16, 2)) +>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak4.ts, 53, 34)) + + >; + }; +}): void; + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak4.ts, 50, 46)) + + actions: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak4.ts, 72, 7)) + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak4.ts, 73, 12)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak4.ts, 42, 10)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak4.ts, 74, 29)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 74, 31)) + + }, +}); + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak4.ts, 50, 46)) + + actions: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak4.ts, 78, 7)) + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak4.ts, 79, 12)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak4.ts, 42, 10)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak4.ts, 80, 29)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 80, 31)) + + doOtherStuff: (_, params: string) => {}, +>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak4.ts, 80, 55)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak4.ts, 81, 19)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 81, 21)) + + }, +}); + +setup({ +>setup : Symbol(setup, Decl(noSilentNeverTypeLeak4.ts, 50, 46)) + + actions: { +>actions : Symbol(actions, Decl(noSilentNeverTypeLeak4.ts, 85, 7)) + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak4.ts, 86, 12)) +>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak4.ts, 42, 10)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak4.ts, 87, 29)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 87, 31)) + + doOtherStuff: (_: any, params: string) => {}, +>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak4.ts, 87, 55)) +>_ : Symbol(_, Decl(noSilentNeverTypeLeak4.ts, 88, 19)) +>params : Symbol(params, Decl(noSilentNeverTypeLeak4.ts, 88, 26)) + + }, +}); + diff --git a/tests/baselines/reference/noSilentNeverTypeLeak4.types b/tests/baselines/reference/noSilentNeverTypeLeak4.types new file mode 100644 index 0000000000000..69973e7ea6c1d --- /dev/null +++ b/tests/baselines/reference/noSilentNeverTypeLeak4.types @@ -0,0 +1,260 @@ +//// [tests/cases/compiler/noSilentNeverTypeLeak4.ts] //// + +=== noSilentNeverTypeLeak4.ts === +type Values = T[keyof T]; +>Values : Values +> : ^^^^^^^^^ + +type MachineContext = Record; +>MachineContext : MachineContext +> : ^^^^^^^^^^^^^^ + +interface ParameterizedObject { + type: string; +>type : string +> : ^^^^^^ + + params?: unknown; +>params : unknown +> : ^^^^^^^ +} + +type ActionFunction< +>ActionFunction : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject, +> = { + (ctx: TContext, params: TParams): void; +>ctx : TContext +> : ^^^^^^^^ +>params : TParams +> : ^^^^^^^ + + _out_TAction?: TAction; +>_out_TAction : TAction | undefined +> : ^^^^^^^^^^^^^^^^^^^ + +}; + +type ToParameterizedObject< +>ToParameterizedObject : ToParameterizedObject +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + TParameterizedMap extends Record< + string, + ParameterizedObject["params"] | undefined + >, +> = Values<{ + [K in keyof TParameterizedMap as K & string]: { + type: K & string; +>type : K & string +> : ^^^^^^^^^^ + + params: TParameterizedMap[K]; +>params : TParameterizedMap[K] +> : ^^^^^^^^^^^^^^^^^^^^ + + }; +}>; + +type CollectActions< +>CollectActions : CollectActions +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, +> = ( + { + context, +>context : TContext +> : ^^^^^^^^ + + enqueue, +>enqueue : (action: () => void) => void +> : ^ ^^ ^^^^^ + + }: { + context: TContext; +>context : TContext +> : ^^^^^^^^ + + enqueue: (action: () => void) => void; +>enqueue : (action: () => void) => void +> : ^ ^^ ^^^^^ +>action : () => void +> : ^^^^^^ + + }, + params: TParams, +>params : TParams +> : ^^^^^^^ + +) => void; + +declare function enqueueActions< +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ + + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject = ParameterizedObject, +>( + collect: CollectActions, +>collect : CollectActions +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +): ActionFunction; + +declare function setup< +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ + + TContext extends MachineContext, + TActions extends Record< + string, + ParameterizedObject["params"] | undefined + > = {}, +>({ + types, +>types : { context?: TContext; } | undefined +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ + + actions, +>actions : { [K in keyof TActions]: ActionFunction>; } | undefined +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +}: { + types?: { context?: TContext }; +>types : { context?: TContext; } | undefined +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^ +>context : TContext | undefined +> : ^^^^^^^^^^^^^^^^^^^^ + + actions?: { +>actions : { [K in keyof TActions]: ActionFunction>; } | undefined +> : ^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + [K in keyof TActions]: ActionFunction< + TContext, + TActions[K], + ToParameterizedObject + >; + }; +}): void; + +setup({ +>setup({ actions: { doStuff: enqueueActions((_, params: number) => {}), },}) : void +> : ^^^^ +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ +>{ actions: { doStuff: enqueueActions((_, params: number) => {}), },} : { actions: { doStuff: ActionFunction; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + actions: { +>actions : { doStuff: ActionFunction; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ doStuff: enqueueActions((_, params: number) => {}), } : { doStuff: ActionFunction; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((_, params: number) => {}) : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ +>(_, params: number) => {} : (_: { context: MachineContext; enqueue: (action: () => void) => void; }, params: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^ ^^^^^^^^^ +>_ : { context: MachineContext; enqueue: (action: () => void) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>params : number +> : ^^^^^^ + + }, +}); + +setup({ +>setup({ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_, params: string) => {}, },}) : void +> : ^^^^ +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ +>{ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_, params: string) => {}, },} : { actions: { doStuff: ActionFunction; doOtherStuff: (_: MachineContext, params: string) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^^^^ + + actions: { +>actions : { doStuff: ActionFunction; doOtherStuff: (_: MachineContext, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ +>{ doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_, params: string) => {}, } : { doStuff: ActionFunction; doOtherStuff: (_: MachineContext, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^^^^ + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((_, params: number) => {}) : ActionFunction +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ +>(_, params: number) => {} : (_: { context: MachineContext; enqueue: (action: () => void) => void; }, params: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^ ^^^^^^^^^ +>_ : { context: MachineContext; enqueue: (action: () => void) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>params : number +> : ^^^^^^ + + doOtherStuff: (_, params: string) => {}, +>doOtherStuff : (_: MachineContext, params: string) => void +> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ +>(_, params: string) => {} : (_: MachineContext, params: string) => void +> : ^ ^^^^^^^^^^^^^^^^^^ ^^ ^^^^^^^^^ +>_ : MachineContext +> : ^^^^^^^^^^^^^^ +>params : string +> : ^^^^^^ + + }, +}); + +setup({ +>setup({ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_: any, params: string) => {}, },}) : void +> : ^^^^ +>setup : = {}>({ types, actions, }: { types?: { context?: TContext; }; actions?: { [K in keyof TActions]: ActionFunction>; }; }) => void +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^ ^^ ^^^^^ +>{ actions: { doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_: any, params: string) => {}, },} : { actions: { doStuff: ActionFunction>; doOtherStuff: (_: any, params: string) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^^^^ + + actions: { +>actions : { doStuff: ActionFunction>; doOtherStuff: (_: any, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^ +>{ doStuff: enqueueActions((_, params: number) => {}), doOtherStuff: (_: any, params: string) => {}, } : { doStuff: ActionFunction>; doOtherStuff: (_: any, params: string) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^ ^^ ^^^^^^^^^^^^ + + doStuff: enqueueActions((_, params: number) => {}), +>doStuff : ActionFunction> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions((_, params: number) => {}) : ActionFunction> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>enqueueActions : (collect: CollectActions) => ActionFunction +> : ^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^ ^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^ ^^^^^ +>(_, params: number) => {} : (_: { context: MachineContext; enqueue: (action: () => void) => void; }, params: number) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^ ^^ ^^^^^^^^^ +>_ : { context: MachineContext; enqueue: (action: () => void) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^ +>params : number +> : ^^^^^^ + + doOtherStuff: (_: any, params: string) => {}, +>doOtherStuff : (_: any, params: string) => void +> : ^ ^^ ^^ ^^ ^^^^^^^^^ +>(_: any, params: string) => {} : (_: any, params: string) => void +> : ^ ^^ ^^ ^^ ^^^^^^^^^ +>_ : any +> : ^^^ +>params : string +> : ^^^^^^ + + }, +}); + diff --git a/tests/cases/compiler/noSilentNeverTypeLeak1.ts b/tests/cases/compiler/noSilentNeverTypeLeak1.ts new file mode 100644 index 0000000000000..0186f50b50159 --- /dev/null +++ b/tests/cases/compiler/noSilentNeverTypeLeak1.ts @@ -0,0 +1,14 @@ +// @strict: true +// @noEmit: true + +type Fn = (arg: T) => void; + +declare function fn1(): Fn; + +declare function fn2( + cb: Fn<{ + [K in keyof T & string]: T[K]; + }>, +): void; + +fn2(fn1()); diff --git a/tests/cases/compiler/noSilentNeverTypeLeak2.ts b/tests/cases/compiler/noSilentNeverTypeLeak2.ts new file mode 100644 index 0000000000000..182f8be7e0d5f --- /dev/null +++ b/tests/cases/compiler/noSilentNeverTypeLeak2.ts @@ -0,0 +1,46 @@ +// @strict: true +// @noEmit: true + +type Values = T[keyof T]; + +interface ParameterizedObject { + type: string; + params?: unknown; +} + +type ActionFunction = { + (params: TParams): void; + _out_TAction?: TAction; +}; + +type ToParameterizedObject = Values<{ + [K in keyof TParameterizedMap & string]: { + type: K; + params: TParameterizedMap[K]; + }; +}>; + +declare function enqueueActions( + collect: (params: TParams) => void, +): ActionFunction; + +declare function setup(actions: { + [K in keyof TActions]: ActionFunction< + TActions[K], + ToParameterizedObject + >; +}): void; + +setup({ + doStuff: enqueueActions((params: number) => {}), +}); + +setup({ + doStuff: enqueueActions((params: number) => {}), + doOtherStuff: (params: string) => {}, +}); + +setup({ + doStuff: enqueueActions((params: number) => {}), + doOtherStuff: (params) => {}, +}); \ No newline at end of file diff --git a/tests/cases/compiler/noSilentNeverTypeLeak3.ts b/tests/cases/compiler/noSilentNeverTypeLeak3.ts new file mode 100644 index 0000000000000..ccdb0d2498561 --- /dev/null +++ b/tests/cases/compiler/noSilentNeverTypeLeak3.ts @@ -0,0 +1,96 @@ +// @strict: true +// @noEmit: true + +// https://github.com/microsoft/TypeScript/issues/62824 + +type Values = T[keyof T]; + +type MachineContext = Record; + +interface ParameterizedObject { + type: string; + params?: unknown; +} + +type ActionFunction< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject, +> = { + (ctx: TContext, params: TParams): void; + _out_TAction?: TAction; +}; + +type ToParameterizedObject< + TParameterizedMap extends Record< + string, + ParameterizedObject["params"] | undefined + >, +> = Values<{ + [K in keyof TParameterizedMap & string]: { + type: K; + params: TParameterizedMap[K]; + }; +}>; + +type CollectActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, +> = ( + { + context, + enqueue, + }: { + context: TContext; + enqueue: (action: () => void) => void; + }, + params: TParams, +) => void; + +declare function enqueueActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject = ParameterizedObject, +>( + collect: CollectActions, +): ActionFunction; + +declare function setup< + TContext extends MachineContext, + TActions extends Record< + string, + ParameterizedObject["params"] | undefined + > = {}, +>({ + types, + actions, +}: { + types?: { context?: TContext }; + actions?: { + [K in keyof TActions]: ActionFunction< + TContext, + TActions[K], + ToParameterizedObject + >; + }; +}): void; + +setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + }, +}); + +setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + doOtherStuff: (_, params: string) => {}, + }, +}); + +setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + doOtherStuff: (_: any, params: string) => {}, + }, +}); diff --git a/tests/cases/compiler/noSilentNeverTypeLeak4.ts b/tests/cases/compiler/noSilentNeverTypeLeak4.ts new file mode 100644 index 0000000000000..48c62c0efd255 --- /dev/null +++ b/tests/cases/compiler/noSilentNeverTypeLeak4.ts @@ -0,0 +1,94 @@ +// @strict: true +// @noEmit: true + +type Values = T[keyof T]; + +type MachineContext = Record; + +interface ParameterizedObject { + type: string; + params?: unknown; +} + +type ActionFunction< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject, +> = { + (ctx: TContext, params: TParams): void; + _out_TAction?: TAction; +}; + +type ToParameterizedObject< + TParameterizedMap extends Record< + string, + ParameterizedObject["params"] | undefined + >, +> = Values<{ + [K in keyof TParameterizedMap as K & string]: { + type: K & string; + params: TParameterizedMap[K]; + }; +}>; + +type CollectActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, +> = ( + { + context, + enqueue, + }: { + context: TContext; + enqueue: (action: () => void) => void; + }, + params: TParams, +) => void; + +declare function enqueueActions< + TContext extends MachineContext, + TParams extends ParameterizedObject["params"] | undefined, + TAction extends ParameterizedObject = ParameterizedObject, +>( + collect: CollectActions, +): ActionFunction; + +declare function setup< + TContext extends MachineContext, + TActions extends Record< + string, + ParameterizedObject["params"] | undefined + > = {}, +>({ + types, + actions, +}: { + types?: { context?: TContext }; + actions?: { + [K in keyof TActions]: ActionFunction< + TContext, + TActions[K], + ToParameterizedObject + >; + }; +}): void; + +setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + }, +}); + +setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + doOtherStuff: (_, params: string) => {}, + }, +}); + +setup({ + actions: { + doStuff: enqueueActions((_, params: number) => {}), + doOtherStuff: (_: any, params: string) => {}, + }, +});