Skip to content

WIP for #44220 #44588

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
wants to merge 1 commit into from
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
9 changes: 7 additions & 2 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7867,7 +7867,10 @@ namespace ts {
}
}
}
return declarationNameToString(name);
if (!(isTransientSymbol(symbol) && symbol.checkFlags & CheckFlags.Mapped
&& isMappedTypeWithKeyofConstraintDeclaration((symbol as MappedSymbol).mappedType))) {
return declarationNameToString(name);
}
}
if (!declaration) {
declaration = symbol.declarations[0]; // Declaration may be nameless, but we'll try anyway
Expand Down Expand Up @@ -19078,7 +19081,9 @@ namespace ts {
if (props.length === 1) {
const propName = symbolToString(unmatchedProperty);
reportError(Diagnostics.Property_0_is_missing_in_type_1_but_required_in_type_2, propName, ...getTypeNamesForErrorDisplay(source, target));
if (length(unmatchedProperty.declarations)) {
if (length(unmatchedProperty.declarations)
&& !(isTransientSymbol(unmatchedProperty) && unmatchedProperty.checkFlags & CheckFlags.Mapped
&& isMappedTypeWithKeyofConstraintDeclaration((unmatchedProperty as MappedSymbol).mappedType))) {
associateRelatedInfo(createDiagnosticForNode(unmatchedProperty.declarations![0], Diagnostics._0_is_declared_here, propName));
}
if (shouldSkipElaboration && errorInfo) {
Expand Down
1 change: 0 additions & 1 deletion tests/baselines/reference/mappedTypeErrors.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ tests/cases/conformance/types/mapped/mappedTypeErrors.ts(152,17): error TS2339:
~~~~~~~~
!!! error TS2345: Argument of type '{ x: number; }' is not assignable to parameter of type 'Readonly<{ x: number; y: number; }>'.
!!! error TS2345: Property 'y' is missing in type '{ x: number; }' but required in type 'Readonly<{ x: number; y: number; }>'.
!!! related TS2728 tests/cases/conformance/types/mapped/mappedTypeErrors.ts:75:37: 'y' is declared here.
let x2 = objAndReadonly({ x: 0, y: 0 }, { x: 1, y: 1 });
let x3 = objAndReadonly({ x: 0, y: 0 }, { x: 1, y: 1, z: 1 }); // Error
~~~~
Expand Down
1 change: 0 additions & 1 deletion tests/baselines/reference/mappedTypes6.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ tests/cases/conformance/types/mapped/mappedTypes6.ts(120,4): error TS2540: Canno
x2 = { a: 1, b: 1, c: 1 }; // Error
~~
!!! error TS2741: Property 'd' is missing in type '{ a: number; b: number; c: number; }' but required in type 'Required<Foo>'.
!!! related TS2728 tests/cases/conformance/types/mapped/mappedTypes6.ts:82:5: 'd' is declared here.
x2 = { a: 1, b: 1, c: 1, d: 1 };

type Bar = {
Expand Down
4 changes: 2 additions & 2 deletions tests/baselines/reference/recursiveMappedTypes.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(11,6): error TS2456
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(12,11): error TS2313: Type parameter 'K' has a circular constraint.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(20,19): error TS2589: Type instantiation is excessively deep and possibly infinite.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(73,5): error TS2502: '"each"' is referenced directly or indirectly in its own type annotation.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(73,13): error TS2615: Type of property '"each"' circularly references itself in mapped type '{ [P in keyof ListWidget]: undefined extends ListWidget[P] ? never : P; }'.
tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(73,13): error TS2615: Type of property 'each' circularly references itself in mapped type '{ [P in keyof ListWidget]: undefined extends ListWidget[P] ? never : P; }'.


==== tests/cases/conformance/types/mapped/recursiveMappedTypes.ts (9 errors) ====
Expand Down Expand Up @@ -101,7 +101,7 @@ tests/cases/conformance/types/mapped/recursiveMappedTypes.ts(73,13): error TS261
~~~~~~
!!! error TS2502: '"each"' is referenced directly or indirectly in its own type annotation.
~~~~~~~~~~~~~~~~~
!!! error TS2615: Type of property '"each"' circularly references itself in mapped type '{ [P in keyof ListWidget]: undefined extends ListWidget[P] ? never : P; }'.
!!! error TS2615: Type of property 'each' circularly references itself in mapped type '{ [P in keyof ListWidget]: undefined extends ListWidget[P] ? never : P; }'.
}

type ListChild = Child<ListWidget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(22,6): error TS
A = b; // Should Error
~
!!! error TS2741: Property 'a' is missing in type 'Required<{ b?: 1; x: 1; }>' but required in type 'Required<{ a?: 1; x: 1; }>'.
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:1:21: 'a' is declared here.
B = a; // Should Error
~
!!! error TS2741: Property 'b' is missing in type 'Required<{ a?: 1; x: 1; }>' but required in type 'Required<{ b?: 1; x: 1; }>'.
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:2:21: 'b' is declared here.

a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
~
Expand All @@ -45,13 +43,11 @@ tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts(22,6): error TS
!!! error TS2322: Type 'Foo<{ b?: 1; x: 1; }>' is not assignable to type 'Foo<{ a?: 1; x: 1; }>'.
!!! error TS2322: Types of property 'a' are incompatible.
!!! error TS2322: Property 'a' is missing in type 'Required<{ b?: 1; x: 1; }>' but required in type 'Required<{ a?: 1; x: 1; }>'.
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:14:17: 'a' is declared here.
BB = aa; // Should Error
~~
!!! error TS2322: Type 'Foo<{ a?: 1; x: 1; }>' is not assignable to type 'Foo<{ b?: 1; x: 1; }>'.
!!! error TS2322: Types of property 'a' are incompatible.
!!! error TS2322: Property 'b' is missing in type 'Required<{ a?: 1; x: 1; }>' but required in type 'Required<{ b?: 1; x: 1; }>'.
!!! related TS2728 tests/cases/compiler/requiredMappedTypeModifierTrumpsVariance.ts:15:17: 'b' is declared here.

aa.a.b; // Property 'b' does not exist on type 'Required<{ a?: 1; x: 1; }>'.
~
Expand Down