Skip to content

Commit 7565a32

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

File tree

9 files changed

+1454
-1
lines changed

9 files changed

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

0 commit comments

Comments
 (0)