Skip to content

Commit 00e3926

Browse files
committed
Defer distributing index over generic object types
1 parent 8b482b5 commit 00e3926

4 files changed

+82
-0
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15903,6 +15903,9 @@ namespace ts {
1590315903
}
1590415904

1590515905
function distributeIndexOverObjectType(objectType: Type, indexType: Type, writing: boolean) {
15906+
if (shouldDeferIndexType(objectType)) {
15907+
return;
15908+
}
1590615909
// (T | U)[K] -> T[K] | U[K] (reading)
1590715910
// (T | U)[K] -> T[K] & U[K] (writing)
1590815911
// (T & U)[K] -> T[K] & U[K]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
=== tests/cases/compiler/mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts ===
2+
interface StateSchema {
3+
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0))
4+
5+
states?: {
6+
>states : Symbol(StateSchema.states, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 23))
7+
8+
[key: string]: StateSchema;
9+
>key : Symbol(key, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 2, 5))
10+
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0))
11+
12+
};
13+
}
14+
15+
declare class StateNode<TStateSchema extends StateSchema> {
16+
>StateNode : Symbol(StateNode, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 4, 1))
17+
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 6, 24))
18+
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0))
19+
20+
schema: TStateSchema;
21+
>schema : Symbol(StateNode.schema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 6, 59))
22+
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 6, 24))
23+
}
24+
25+
type StateNodesConfig<TStateSchema extends StateSchema> = {
26+
>StateNodesConfig : Symbol(StateNodesConfig, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 8, 1))
27+
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 10, 22))
28+
>StateSchema : Symbol(StateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 0, 0))
29+
30+
[K in keyof TStateSchema["states"]]: StateNode<NonNullable<TStateSchema["states"]>[K]>;
31+
>K : Symbol(K, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 11, 3))
32+
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 10, 22))
33+
>StateNode : Symbol(StateNode, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 4, 1))
34+
>NonNullable : Symbol(NonNullable, Decl(lib.es5.d.ts, --, --))
35+
>TStateSchema : Symbol(TStateSchema, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 10, 22))
36+
>K : Symbol(K, Decl(mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts, 11, 3))
37+
38+
};
39+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
=== tests/cases/compiler/mappedTypeOverNullableConstraintWithIndexSignatureWithNonNullable.ts ===
2+
interface StateSchema {
3+
states?: {
4+
>states : { [key: string]: StateSchema; } | undefined
5+
6+
[key: string]: StateSchema;
7+
>key : string
8+
9+
};
10+
}
11+
12+
declare class StateNode<TStateSchema extends StateSchema> {
13+
>StateNode : StateNode<TStateSchema>
14+
15+
schema: TStateSchema;
16+
>schema : TStateSchema
17+
}
18+
19+
type StateNodesConfig<TStateSchema extends StateSchema> = {
20+
>StateNodesConfig : StateNodesConfig<TStateSchema>
21+
22+
[K in keyof TStateSchema["states"]]: StateNode<NonNullable<TStateSchema["states"]>[K]>;
23+
};
24+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @noEmit: true
2+
// @strict: true
3+
4+
interface StateSchema {
5+
states?: {
6+
[key: string]: StateSchema;
7+
};
8+
}
9+
10+
declare class StateNode<TStateSchema extends StateSchema> {
11+
schema: TStateSchema;
12+
}
13+
14+
type StateNodesConfig<TStateSchema extends StateSchema> = {
15+
[K in keyof TStateSchema["states"]]: StateNode<NonNullable<TStateSchema["states"]>[K]>;
16+
};

0 commit comments

Comments
 (0)