diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index cb1d53714f44d..2ab5d723a0d62 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -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 @@ -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) { diff --git a/tests/baselines/reference/mappedTypeErrors.errors.txt b/tests/baselines/reference/mappedTypeErrors.errors.txt index b2c59fce02c00..86e10335b518f 100644 --- a/tests/baselines/reference/mappedTypeErrors.errors.txt +++ b/tests/baselines/reference/mappedTypeErrors.errors.txt @@ -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 ~~~~ diff --git a/tests/baselines/reference/mappedTypes6.errors.txt b/tests/baselines/reference/mappedTypes6.errors.txt index 2429ea8558f10..1fa2a91f730cd 100644 --- a/tests/baselines/reference/mappedTypes6.errors.txt +++ b/tests/baselines/reference/mappedTypes6.errors.txt @@ -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'. -!!! 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 = { diff --git a/tests/baselines/reference/recursiveMappedTypes.errors.txt b/tests/baselines/reference/recursiveMappedTypes.errors.txt index 1a912efef0fe9..e8c089cb39a3a 100644 --- a/tests/baselines/reference/recursiveMappedTypes.errors.txt +++ b/tests/baselines/reference/recursiveMappedTypes.errors.txt @@ -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) ==== @@ -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 diff --git a/tests/baselines/reference/requiredMappedTypeModifierTrumpsVariance.errors.txt b/tests/baselines/reference/requiredMappedTypeModifierTrumpsVariance.errors.txt index 83871b2909688..8412f431db796 100644 --- a/tests/baselines/reference/requiredMappedTypeModifierTrumpsVariance.errors.txt +++ b/tests/baselines/reference/requiredMappedTypeModifierTrumpsVariance.errors.txt @@ -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; }>'. ~ @@ -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; }>'. ~