mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Issue implicit any errors for mapped types without annotations (#21104)
* Fixed #21011 * Updated code of merged message * Reversed message code change and moved error to it's appropriate position * Applied suggested improvements * Fixed wrong diagnostics message in checker * Reverted diagnostic message change
This commit is contained in:
parent
8bce69e6bd
commit
03fd77657d
@ -11281,6 +11281,9 @@ namespace ts {
|
||||
}
|
||||
diagnostic = Diagnostics._0_which_lacks_return_type_annotation_implicitly_has_an_1_return_type;
|
||||
break;
|
||||
case SyntaxKind.MappedType:
|
||||
error(declaration, Diagnostics.Mapped_object_type_implicitly_has_an_any_template_type);
|
||||
return;
|
||||
default:
|
||||
diagnostic = Diagnostics.Variable_0_implicitly_has_an_1_type;
|
||||
}
|
||||
@ -20312,6 +20315,11 @@ namespace ts {
|
||||
function checkMappedType(node: MappedTypeNode) {
|
||||
checkSourceElement(node.typeParameter);
|
||||
checkSourceElement(node.type);
|
||||
|
||||
if (noImplicitAny && !node.type) {
|
||||
reportImplicitAnyError(node, anyType);
|
||||
}
|
||||
|
||||
const type = <MappedType>getTypeFromMappedTypeNode(node);
|
||||
const constraintType = getConstraintTypeFromMappedType(type);
|
||||
checkTypeAssignableTo(constraintType, stringType, node.typeParameter.constraint);
|
||||
|
||||
@ -3571,7 +3571,10 @@
|
||||
"category": "Error",
|
||||
"code": 7038
|
||||
},
|
||||
|
||||
"Mapped object type implicitly has an 'any' template type.": {
|
||||
"category": "Error",
|
||||
"code": 7039
|
||||
},
|
||||
"You cannot rename this element.": {
|
||||
"category": "Error",
|
||||
"code": 8000
|
||||
|
||||
7
tests/baselines/reference/anyMappedTypesError.errors.txt
Normal file
7
tests/baselines/reference/anyMappedTypesError.errors.txt
Normal file
@ -0,0 +1,7 @@
|
||||
tests/cases/compiler/anyMappedTypesError.ts(1,12): error TS7039: Mapped object type implicitly has an 'any' template type.
|
||||
|
||||
|
||||
==== tests/cases/compiler/anyMappedTypesError.ts (1 errors) ====
|
||||
type Foo = {[P in "bar"]};
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS7039: Mapped object type implicitly has an 'any' template type.
|
||||
4
tests/baselines/reference/anyMappedTypesError.js
Normal file
4
tests/baselines/reference/anyMappedTypesError.js
Normal file
@ -0,0 +1,4 @@
|
||||
//// [anyMappedTypesError.ts]
|
||||
type Foo = {[P in "bar"]};
|
||||
|
||||
//// [anyMappedTypesError.js]
|
||||
5
tests/baselines/reference/anyMappedTypesError.symbols
Normal file
5
tests/baselines/reference/anyMappedTypesError.symbols
Normal file
@ -0,0 +1,5 @@
|
||||
=== tests/cases/compiler/anyMappedTypesError.ts ===
|
||||
type Foo = {[P in "bar"]};
|
||||
>Foo : Symbol(Foo, Decl(anyMappedTypesError.ts, 0, 0))
|
||||
>P : Symbol(P, Decl(anyMappedTypesError.ts, 0, 13))
|
||||
|
||||
5
tests/baselines/reference/anyMappedTypesError.types
Normal file
5
tests/baselines/reference/anyMappedTypesError.types
Normal file
@ -0,0 +1,5 @@
|
||||
=== tests/cases/compiler/anyMappedTypesError.ts ===
|
||||
type Foo = {[P in "bar"]};
|
||||
>Foo : Foo
|
||||
>P : P
|
||||
|
||||
3
tests/cases/compiler/anyMappedTypesError.ts
Normal file
3
tests/cases/compiler/anyMappedTypesError.ts
Normal file
@ -0,0 +1,3 @@
|
||||
// @noImplicitAny: true
|
||||
|
||||
type Foo = {[P in "bar"]};
|
||||
Loading…
x
Reference in New Issue
Block a user