Skip to content

Test: Revert "Merge pull request #32071 from andrewbranch/bug/31070" #32370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13443,14 +13443,14 @@ namespace ts {
if (!isGenericMappedType(source)) {
const targetConstraint = getConstraintTypeFromMappedType(target);
const sourceKeys = getIndexType(source, /*stringsOnly*/ undefined, /*noIndexSignatures*/ true);
const includeOptional = modifiers & MappedTypeModifiers.IncludeOptional;
const filteredByApplicability = includeOptional ? intersectTypes(targetConstraint, sourceKeys) : undefined;
const hasOptionalUnionKeys = modifiers & MappedTypeModifiers.IncludeOptional && targetConstraint.flags & TypeFlags.Union;
const filteredByApplicability = hasOptionalUnionKeys ? filterType(targetConstraint, t => !!isRelatedTo(t, sourceKeys)) : undefined;
// 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.
// 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.
if (includeOptional
if (hasOptionalUnionKeys
? !(filteredByApplicability!.flags & TypeFlags.Never)
: isRelatedTo(targetConstraint, sourceKeys)) {
const indexingType = filteredByApplicability || getTypeParameterFromMappedType(target);
const indexingType = hasOptionalUnionKeys ? filteredByApplicability! : getTypeParameterFromMappedType(target);
const indexedAccessType = getIndexedAccessType(source, indexingType);
const templateType = getTemplateTypeFromMappedType(target);
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
Expand Down

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions tests/baselines/reference/mappedTypeRelationships.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,4 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(168,5): error TS
function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2): Partial<T[K1][K2]> {
return t[k1][k2];
}

// #31070
type Numeric<T> = { [K in keyof T]?: number };
function f90<T extends { x: number }>() {
const n: Numeric<T> = { x: 1 };
}

15 changes: 0 additions & 15 deletions tests/baselines/reference/mappedTypeRelationships.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,6 @@ function f81<T, K extends keyof T>(t: T, k: K): Partial<T[K]> {
function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2): Partial<T[K1][K2]> {
return t[k1][k2];
}

// #31070
type Numeric<T> = { [K in keyof T]?: number };
function f90<T extends { x: number }>() {
const n: Numeric<T> = { x: 1 };
}


//// [mappedTypeRelationships.js]
Expand Down Expand Up @@ -316,9 +310,6 @@ function f81(t, k) {
function f82(t, k1, k2) {
return t[k1][k2];
}
function f90() {
var n = { x: 1 };
}


//// [mappedTypeRelationships.d.ts]
Expand Down Expand Up @@ -402,9 +393,3 @@ declare function f76<T, U extends T, K extends keyof T>(x: {
declare function f80<T>(t: T): Partial<T>;
declare function f81<T, K extends keyof T>(t: T, k: K): Partial<T[K]>;
declare function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2): Partial<T[K1][K2]>;
declare type Numeric<T> = {
[K in keyof T]?: number;
};
declare function f90<T extends {
x: number;
}>(): void;
19 changes: 0 additions & 19 deletions tests/baselines/reference/mappedTypeRelationships.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -805,22 +805,3 @@ function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2
>k2 : Symbol(k2, Decl(mappedTypeRelationships.ts, 178, 73))
}

// #31070
type Numeric<T> = { [K in keyof T]?: number };
>Numeric : Symbol(Numeric, Decl(mappedTypeRelationships.ts, 180, 1))
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 183, 13))
>K : Symbol(K, Decl(mappedTypeRelationships.ts, 183, 21))
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 183, 13))

function f90<T extends { x: number }>() {
>f90 : Symbol(f90, Decl(mappedTypeRelationships.ts, 183, 46))
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 184, 13))
>x : Symbol(x, Decl(mappedTypeRelationships.ts, 184, 24))

const n: Numeric<T> = { x: 1 };
>n : Symbol(n, Decl(mappedTypeRelationships.ts, 185, 9))
>Numeric : Symbol(Numeric, Decl(mappedTypeRelationships.ts, 180, 1))
>T : Symbol(T, Decl(mappedTypeRelationships.ts, 184, 13))
>x : Symbol(x, Decl(mappedTypeRelationships.ts, 185, 27))
}

15 changes: 0 additions & 15 deletions tests/baselines/reference/mappedTypeRelationships.types
Original file line number Diff line number Diff line change
Expand Up @@ -653,18 +653,3 @@ function f82<T, K1 extends keyof T, K2 extends keyof T[K1]>(t: T, k1: K1, k2: K2
>k2 : K2
}

// #31070
type Numeric<T> = { [K in keyof T]?: number };
>Numeric : Numeric<T>

function f90<T extends { x: number }>() {
>f90 : <T extends { x: number; }>() => void
>x : number

const n: Numeric<T> = { x: 1 };
>n : Numeric<T>
>{ x: 1 } : { x: number; }
>x : number
>1 : 1
}

Loading