Skip to content

Commit 6d32b54

Browse files
committed
Revert "Merge pull request microsoft#32071 from andrewbranch/bug/31070"
This reverts commit 327bc3c, reversing changes made to c91e147.
1 parent ea73093 commit 6d32b54

8 files changed

+120
-261
lines changed

src/compiler/checker.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -13443,14 +13443,14 @@ namespace ts {
1344313443
if (!isGenericMappedType(source)) {
1344413444
const targetConstraint = getConstraintTypeFromMappedType(target);
1344513445
const sourceKeys = getIndexType(source, /*stringsOnly*/ undefined, /*noIndexSignatures*/ true);
13446-
const includeOptional = modifiers & MappedTypeModifiers.IncludeOptional;
13447-
const filteredByApplicability = includeOptional ? intersectTypes(targetConstraint, sourceKeys) : undefined;
13446+
const hasOptionalUnionKeys = modifiers & MappedTypeModifiers.IncludeOptional && targetConstraint.flags & TypeFlags.Union;
13447+
const filteredByApplicability = hasOptionalUnionKeys ? filterType(targetConstraint, t => !!isRelatedTo(t, sourceKeys)) : undefined;
1344813448
// A source type T is related to a target type { [P in Q]: X } if Q is related to keyof T and T[Q] is related to X.
1344913449
// A source type T is related to a target type { [P in Q]?: X } if some constituent Q' of Q is related to keyof T and T[Q'] is related to X.
13450-
if (includeOptional
13450+
if (hasOptionalUnionKeys
1345113451
? !(filteredByApplicability!.flags & TypeFlags.Never)
1345213452
: isRelatedTo(targetConstraint, sourceKeys)) {
13453-
const indexingType = filteredByApplicability || getTypeParameterFromMappedType(target);
13453+
const indexingType = hasOptionalUnionKeys ? filteredByApplicability! : getTypeParameterFromMappedType(target);
1345413454
const indexedAccessType = getIndexedAccessType(source, indexingType);
1345513455
const templateType = getTemplateTypeFromMappedType(target);
1345613456
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {

tests/baselines/reference/circularlyConstrainedMappedTypeContainingConditionalNoInfiniteInstantiationDepth.errors.txt

+58-98
Large diffs are not rendered by default.

tests/baselines/reference/mappedTypeRelationships.errors.txt

-6
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,4 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS
386386
function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2): Partial<T[K1][K2]> {
387387
return t[k1][k2];
388388
}
389-
390-
// #31070
391-
type Numeric<T> = { [K in keyof T]?: number };
392-
function f90<T extends { x: number }>() {
393-
const n: Numeric<T> = { x: 1 };
394-
}
395389

tests/baselines/reference/mappedTypeRelationships.js

-15
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,6 @@ function f81<T, K extends keyof T>(t: T, k: K): Partial<T[K]> {
180180
function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2): Partial<T[K1][K2]> {
181181
return t[k1][k2];
182182
}
183-
184-
// #31070
185-
type Numeric<T> = { [K in keyof T]?: number };
186-
function f90<T extends { x: number }>() {
187-
const n: Numeric<T> = { x: 1 };
188-
}
189183

190184

191185
//// [mappedTypeRelationships.js]
@@ -316,9 +310,6 @@ function f81(t, k) {
316310
function f82(t, k1, k2) {
317311
return t[k1][k2];
318312
}
319-
function f90() {
320-
var n = { x: 1 };
321-
}
322313

323314

324315
//// [mappedTypeRelationships.d.ts]
@@ -402,9 +393,3 @@ declare function f76<T, U extends T, K extends keyof T>(x: {
402393
declare function f80<T>(t: T): Partial<T>;
403394
declare function f81<T, K extends keyof T>(t: T, k: K): Partial<T[K]>;
404395
declare function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2): Partial<T[K1][K2]>;
405-
declare type Numeric<T> = {
406-
[K in keyof T]?: number;
407-
};
408-
declare function f90<T extends {
409-
x: number;
410-
}>(): void;

tests/baselines/reference/mappedTypeRelationships.symbols

-19
Original file line numberDiff line numberDiff line change
@@ -805,22 +805,3 @@ function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2
805805
>k2 : Symbol(k2, Decl(mappedTypeRelationships.ts, 178, 73))
806806
}
807807

808-
// #31070
809-
type Numeric<T> = { [K in keyof T]?: number };
810-
>Numeric : Symbol(Numeric, Decl(mappedTypeRelationships.ts, 180, 1))
811-
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 183, 13))
812-
>K : Symbol(K, Decl(mappedTypeRelationships.ts, 183, 21))
813-
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 183, 13))
814-
815-
function f90<T extends { x: number }>() {
816-
>f90 : Symbol(f90, Decl(mappedTypeRelationships.ts, 183, 46))
817-
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 184, 13))
818-
>x : Symbol(x, Decl(mappedTypeRelationships.ts, 184, 24))
819-
820-
const n: Numeric<T> = { x: 1 };
821-
>n : Symbol(n, Decl(mappedTypeRelationships.ts, 185, 9))
822-
>Numeric : Symbol(Numeric, Decl(mappedTypeRelationships.ts, 180, 1))
823-
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 184, 13))
824-
>x : Symbol(x, Decl(mappedTypeRelationships.ts, 185, 27))
825-
}
826-

tests/baselines/reference/mappedTypeRelationships.types

-15
Original file line numberDiff line numberDiff line change
@@ -653,18 +653,3 @@ function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2
653653
>k2 : K2
654654
}
655655

656-
// #31070
657-
type Numeric<T> = { [K in keyof T]?: number };
658-
>Numeric : Numeric<T>
659-
660-
function f90<T extends { x: number }>() {
661-
>f90 : <T extends { x: number; }>() => void
662-
>x : number
663-
664-
const n: Numeric<T> = { x: 1 };
665-
>n : Numeric<T>
666-
>{ x: 1 } : { x: number; }
667-
>x : number
668-
>1 : 1
669-
}
670-

0 commit comments

Comments
 (0)