Skip to content

Commit 59bda8f

Browse files
committed
Fixed silentNeverType leak by propagating it through getIndexType
1 parent 5026c66 commit 59bda8f

File tree

9 files changed

+1460
-1
lines changed

9 files changed

+1460
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18932,7 +18932,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
1893218932
type.flags & TypeFlags.Union ? getIntersectionType(map((type as UnionType).types, t => getIndexType(t, indexFlags))) :
1893318933
type.flags & TypeFlags.Intersection ? getUnionType(map((type as IntersectionType).types, t => getIndexType(t, indexFlags))) :
1893418934
getObjectFlags(type) & ObjectFlags.Mapped ? getIndexTypeForMappedType(type as MappedType, indexFlags) :
18935-
type === wildcardType ? wildcardType :
18935+
type === wildcardType || type === silentNeverType ? type :
1893618936
type.flags & TypeFlags.Unknown ? neverType :
1893718937
type.flags & (TypeFlags.Any | TypeFlags.Never) ? stringNumberSymbolType :
1893818938
getLiteralTypeFromProperties(type, (indexFlags & IndexFlags.NoIndexSignatures ? TypeFlags.StringLiteral : TypeFlags.StringLike) | (indexFlags & IndexFlags.StringsOnly ? 0 : TypeFlags.NumberLike | TypeFlags.ESSymbolLike), indexFlags === IndexFlags.None);
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
noSilentNeverTypeLeak1.ts(90,5): error TS2322: Type 'ActionFunction<MachineContext, number, ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>>' is not assignable to type 'ActionFunction<MachineContext, number, ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>>'.
2+
Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'.
3+
Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'.
4+
Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'.
5+
Types of property 'params' are incompatible.
6+
Type 'unknown' is not assignable to type 'number'.
7+
8+
9+
==== noSilentNeverTypeLeak1.ts (1 errors) ====
10+
// https://github.com/microsoft/TypeScript/issues/62824
11+
12+
type Values<T> = T[keyof T];
13+
14+
type MachineContext = Record<string, any>;
15+
16+
interface ParameterizedObject {
17+
type: string;
18+
params?: unknown;
19+
}
20+
21+
type ActionFunction<
22+
TContext extends MachineContext,
23+
TParams extends ParameterizedObject["params"] | undefined,
24+
TAction extends ParameterizedObject,
25+
> = {
26+
(ctx: TContext, params: TParams): void;
27+
_out_TAction?: TAction;
28+
};
29+
30+
type ToParameterizedObject<
31+
TParameterizedMap extends Record<
32+
string,
33+
ParameterizedObject["params"] | undefined
34+
>,
35+
> = Values<{
36+
[K in keyof TParameterizedMap & string]: {
37+
type: K;
38+
params: TParameterizedMap[K];
39+
};
40+
}>;
41+
42+
type CollectActions<
43+
TContext extends MachineContext,
44+
TParams extends ParameterizedObject["params"] | undefined,
45+
> = (
46+
{
47+
context,
48+
enqueue,
49+
}: {
50+
context: TContext;
51+
enqueue: (action: () => void) => void;
52+
},
53+
params: TParams,
54+
) => void;
55+
56+
declare function enqueueActions<
57+
TContext extends MachineContext,
58+
TParams extends ParameterizedObject["params"] | undefined,
59+
TAction extends ParameterizedObject = ParameterizedObject,
60+
>(
61+
collect: CollectActions<TContext, TParams>,
62+
): ActionFunction<TContext, TParams, TAction>;
63+
64+
declare function setup<
65+
TContext extends MachineContext,
66+
TActions extends Record<
67+
string,
68+
ParameterizedObject["params"] | undefined
69+
> = {},
70+
>({
71+
types,
72+
actions,
73+
}: {
74+
types?: { context?: TContext };
75+
actions?: {
76+
[K in keyof TActions]: ActionFunction<
77+
TContext,
78+
TActions[K],
79+
ToParameterizedObject<TActions>
80+
>;
81+
};
82+
}): void;
83+
84+
setup({
85+
actions: {
86+
doStuff: enqueueActions((_, params: number) => {}),
87+
},
88+
});
89+
90+
setup({
91+
actions: {
92+
doStuff: enqueueActions((_, params: number) => {}),
93+
doOtherStuff: (_, params: string) => {},
94+
},
95+
});
96+
97+
setup({
98+
actions: {
99+
doStuff: enqueueActions((_, params: number) => {}),
100+
~~~~~~~
101+
!!! error TS2322: Type 'ActionFunction<MachineContext, number, ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>>' is not assignable to type 'ActionFunction<MachineContext, number, ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>>'.
102+
!!! error TS2322: Type 'ToParameterizedObject<{ doStuff: unknown; doOtherStuff: string; }>' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'.
103+
!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type 'ToParameterizedObject<{ doStuff: number; doOtherStuff: string; }>'.
104+
!!! error TS2322: Type '{ type: "doStuff"; params: unknown; }' is not assignable to type '{ type: "doStuff"; params: number; }'.
105+
!!! error TS2322: Types of property 'params' are incompatible.
106+
!!! error TS2322: Type 'unknown' is not assignable to type 'number'.
107+
doOtherStuff: (_: any, params: string) => {},
108+
},
109+
});
110+
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
//// [tests/cases/compiler/noSilentNeverTypeLeak1.ts] ////
2+
3+
=== noSilentNeverTypeLeak1.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/62824
5+
6+
type Values<T> = T[keyof T];
7+
>Values : Symbol(Values, Decl(noSilentNeverTypeLeak1.ts, 0, 0))
8+
>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 2, 12))
9+
>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 2, 12))
10+
>T : Symbol(T, Decl(noSilentNeverTypeLeak1.ts, 2, 12))
11+
12+
type MachineContext = Record<string, any>;
13+
>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak1.ts, 2, 28))
14+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
15+
16+
interface ParameterizedObject {
17+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
18+
19+
type: string;
20+
>type : Symbol(ParameterizedObject.type, Decl(noSilentNeverTypeLeak1.ts, 6, 31))
21+
22+
params?: unknown;
23+
>params : Symbol(ParameterizedObject.params, Decl(noSilentNeverTypeLeak1.ts, 7, 15))
24+
}
25+
26+
type ActionFunction<
27+
>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak1.ts, 9, 1))
28+
29+
TContext extends MachineContext,
30+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 11, 20))
31+
>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak1.ts, 2, 28))
32+
33+
TParams extends ParameterizedObject["params"] | undefined,
34+
>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak1.ts, 12, 34))
35+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
36+
37+
TAction extends ParameterizedObject,
38+
>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak1.ts, 13, 60))
39+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
40+
41+
> = {
42+
(ctx: TContext, params: TParams): void;
43+
>ctx : Symbol(ctx, Decl(noSilentNeverTypeLeak1.ts, 16, 3))
44+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 11, 20))
45+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 16, 17))
46+
>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak1.ts, 12, 34))
47+
48+
_out_TAction?: TAction;
49+
>_out_TAction : Symbol(_out_TAction, Decl(noSilentNeverTypeLeak1.ts, 16, 41))
50+
>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak1.ts, 13, 60))
51+
52+
};
53+
54+
type ToParameterizedObject<
55+
>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 18, 2))
56+
57+
TParameterizedMap extends Record<
58+
>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak1.ts, 20, 27))
59+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
60+
61+
string,
62+
ParameterizedObject["params"] | undefined
63+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
64+
65+
>,
66+
> = Values<{
67+
>Values : Symbol(Values, Decl(noSilentNeverTypeLeak1.ts, 0, 0))
68+
69+
[K in keyof TParameterizedMap & string]: {
70+
>K : Symbol(K, Decl(noSilentNeverTypeLeak1.ts, 26, 3))
71+
>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak1.ts, 20, 27))
72+
73+
type: K;
74+
>type : Symbol(type, Decl(noSilentNeverTypeLeak1.ts, 26, 44))
75+
>K : Symbol(K, Decl(noSilentNeverTypeLeak1.ts, 26, 3))
76+
77+
params: TParameterizedMap[K];
78+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 27, 12))
79+
>TParameterizedMap : Symbol(TParameterizedMap, Decl(noSilentNeverTypeLeak1.ts, 20, 27))
80+
>K : Symbol(K, Decl(noSilentNeverTypeLeak1.ts, 26, 3))
81+
82+
};
83+
}>;
84+
85+
type CollectActions<
86+
>CollectActions : Symbol(CollectActions, Decl(noSilentNeverTypeLeak1.ts, 30, 3))
87+
88+
TContext extends MachineContext,
89+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 32, 20))
90+
>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak1.ts, 2, 28))
91+
92+
TParams extends ParameterizedObject["params"] | undefined,
93+
>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak1.ts, 33, 34))
94+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
95+
96+
> = (
97+
{
98+
context,
99+
>context : Symbol(context, Decl(noSilentNeverTypeLeak1.ts, 36, 3))
100+
101+
enqueue,
102+
>enqueue : Symbol(enqueue, Decl(noSilentNeverTypeLeak1.ts, 37, 12))
103+
104+
}: {
105+
context: TContext;
106+
>context : Symbol(context, Decl(noSilentNeverTypeLeak1.ts, 39, 6))
107+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 32, 20))
108+
109+
enqueue: (action: () => void) => void;
110+
>enqueue : Symbol(enqueue, Decl(noSilentNeverTypeLeak1.ts, 40, 22))
111+
>action : Symbol(action, Decl(noSilentNeverTypeLeak1.ts, 41, 14))
112+
113+
},
114+
params: TParams,
115+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 42, 4))
116+
>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak1.ts, 33, 34))
117+
118+
) => void;
119+
120+
declare function enqueueActions<
121+
>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak1.ts, 44, 10))
122+
123+
TContext extends MachineContext,
124+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 46, 32))
125+
>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak1.ts, 2, 28))
126+
127+
TParams extends ParameterizedObject["params"] | undefined,
128+
>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak1.ts, 47, 34))
129+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
130+
131+
TAction extends ParameterizedObject = ParameterizedObject,
132+
>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak1.ts, 48, 60))
133+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
134+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
135+
136+
>(
137+
collect: CollectActions<TContext, TParams>,
138+
>collect : Symbol(collect, Decl(noSilentNeverTypeLeak1.ts, 50, 2))
139+
>CollectActions : Symbol(CollectActions, Decl(noSilentNeverTypeLeak1.ts, 30, 3))
140+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 46, 32))
141+
>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak1.ts, 47, 34))
142+
143+
): ActionFunction<TContext, TParams, TAction>;
144+
>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak1.ts, 9, 1))
145+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 46, 32))
146+
>TParams : Symbol(TParams, Decl(noSilentNeverTypeLeak1.ts, 47, 34))
147+
>TAction : Symbol(TAction, Decl(noSilentNeverTypeLeak1.ts, 48, 60))
148+
149+
declare function setup<
150+
>setup : Symbol(setup, Decl(noSilentNeverTypeLeak1.ts, 52, 46))
151+
152+
TContext extends MachineContext,
153+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 54, 23))
154+
>MachineContext : Symbol(MachineContext, Decl(noSilentNeverTypeLeak1.ts, 2, 28))
155+
156+
TActions extends Record<
157+
>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak1.ts, 55, 34))
158+
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))
159+
160+
string,
161+
ParameterizedObject["params"] | undefined
162+
>ParameterizedObject : Symbol(ParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 4, 42))
163+
164+
> = {},
165+
>({
166+
types,
167+
>types : Symbol(types, Decl(noSilentNeverTypeLeak1.ts, 60, 3))
168+
169+
actions,
170+
>actions : Symbol(actions, Decl(noSilentNeverTypeLeak1.ts, 61, 8))
171+
172+
}: {
173+
types?: { context?: TContext };
174+
>types : Symbol(types, Decl(noSilentNeverTypeLeak1.ts, 63, 4))
175+
>context : Symbol(context, Decl(noSilentNeverTypeLeak1.ts, 64, 11))
176+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 54, 23))
177+
178+
actions?: {
179+
>actions : Symbol(actions, Decl(noSilentNeverTypeLeak1.ts, 64, 33))
180+
181+
[K in keyof TActions]: ActionFunction<
182+
>K : Symbol(K, Decl(noSilentNeverTypeLeak1.ts, 66, 5))
183+
>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak1.ts, 55, 34))
184+
>ActionFunction : Symbol(ActionFunction, Decl(noSilentNeverTypeLeak1.ts, 9, 1))
185+
186+
TContext,
187+
>TContext : Symbol(TContext, Decl(noSilentNeverTypeLeak1.ts, 54, 23))
188+
189+
TActions[K],
190+
>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak1.ts, 55, 34))
191+
>K : Symbol(K, Decl(noSilentNeverTypeLeak1.ts, 66, 5))
192+
193+
ToParameterizedObject<TActions>
194+
>ToParameterizedObject : Symbol(ToParameterizedObject, Decl(noSilentNeverTypeLeak1.ts, 18, 2))
195+
>TActions : Symbol(TActions, Decl(noSilentNeverTypeLeak1.ts, 55, 34))
196+
197+
>;
198+
};
199+
}): void;
200+
201+
setup({
202+
>setup : Symbol(setup, Decl(noSilentNeverTypeLeak1.ts, 52, 46))
203+
204+
actions: {
205+
>actions : Symbol(actions, Decl(noSilentNeverTypeLeak1.ts, 74, 7))
206+
207+
doStuff: enqueueActions((_, params: number) => {}),
208+
>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak1.ts, 75, 12))
209+
>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak1.ts, 44, 10))
210+
>_ : Symbol(_, Decl(noSilentNeverTypeLeak1.ts, 76, 29))
211+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 76, 31))
212+
213+
},
214+
});
215+
216+
setup({
217+
>setup : Symbol(setup, Decl(noSilentNeverTypeLeak1.ts, 52, 46))
218+
219+
actions: {
220+
>actions : Symbol(actions, Decl(noSilentNeverTypeLeak1.ts, 80, 7))
221+
222+
doStuff: enqueueActions((_, params: number) => {}),
223+
>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak1.ts, 81, 12))
224+
>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak1.ts, 44, 10))
225+
>_ : Symbol(_, Decl(noSilentNeverTypeLeak1.ts, 82, 29))
226+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 82, 31))
227+
228+
doOtherStuff: (_, params: string) => {},
229+
>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak1.ts, 82, 55))
230+
>_ : Symbol(_, Decl(noSilentNeverTypeLeak1.ts, 83, 19))
231+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 83, 21))
232+
233+
},
234+
});
235+
236+
setup({
237+
>setup : Symbol(setup, Decl(noSilentNeverTypeLeak1.ts, 52, 46))
238+
239+
actions: {
240+
>actions : Symbol(actions, Decl(noSilentNeverTypeLeak1.ts, 87, 7))
241+
242+
doStuff: enqueueActions((_, params: number) => {}),
243+
>doStuff : Symbol(doStuff, Decl(noSilentNeverTypeLeak1.ts, 88, 12))
244+
>enqueueActions : Symbol(enqueueActions, Decl(noSilentNeverTypeLeak1.ts, 44, 10))
245+
>_ : Symbol(_, Decl(noSilentNeverTypeLeak1.ts, 89, 29))
246+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 89, 31))
247+
248+
doOtherStuff: (_: any, params: string) => {},
249+
>doOtherStuff : Symbol(doOtherStuff, Decl(noSilentNeverTypeLeak1.ts, 89, 55))
250+
>_ : Symbol(_, Decl(noSilentNeverTypeLeak1.ts, 90, 19))
251+
>params : Symbol(params, Decl(noSilentNeverTypeLeak1.ts, 90, 26))
252+
253+
},
254+
});
255+

0 commit comments

Comments
 (0)