Fix error message for implicit-any property in object literal with symbol key (#21883)

This commit is contained in:
Andy
2018-02-12 11:09:50 -08:00
committed by GitHub
parent 67984c720e
commit 2d80253d09
6 changed files with 50 additions and 1 deletions
+1 -1
View File
@@ -11203,7 +11203,7 @@ namespace ts {
const t = getTypeOfSymbol(p);
if (t.flags & TypeFlags.ContainsWideningType) {
if (!reportWideningErrorsInType(t)) {
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, symbolName(p), typeToString(getWidenedType(t)));
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, symbolToString(p), typeToString(getWidenedType(t)));
}
errorReported = true;
}
@@ -0,0 +1,9 @@
tests/cases/compiler/objectLiteralPropertyImplicitlyAny.ts(2,13): error TS7018: Object literal's property '[foo]' implicitly has an 'any' type.
==== tests/cases/compiler/objectLiteralPropertyImplicitlyAny.ts (1 errors) ====
const foo = Symbol.for("foo");
const o = { [foo]: undefined };
~~~~~~~~~~~~~~~~
!!! error TS7018: Object literal's property '[foo]' implicitly has an 'any' type.
@@ -0,0 +1,8 @@
//// [objectLiteralPropertyImplicitlyAny.ts]
const foo = Symbol.for("foo");
const o = { [foo]: undefined };
//// [objectLiteralPropertyImplicitlyAny.js]
const foo = Symbol.for("foo");
const o = { [foo]: undefined };
@@ -0,0 +1,12 @@
=== tests/cases/compiler/objectLiteralPropertyImplicitlyAny.ts ===
const foo = Symbol.for("foo");
>foo : Symbol(foo, Decl(objectLiteralPropertyImplicitlyAny.ts, 0, 5))
>Symbol.for : Symbol(SymbolConstructor.for, Decl(lib.es2015.symbol.d.ts, --, --))
>Symbol : Symbol(Symbol, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --), Decl(lib.es2015.symbol.d.ts, --, --))
>for : Symbol(SymbolConstructor.for, Decl(lib.es2015.symbol.d.ts, --, --))
const o = { [foo]: undefined };
>o : Symbol(o, Decl(objectLiteralPropertyImplicitlyAny.ts, 1, 5))
>foo : Symbol(foo, Decl(objectLiteralPropertyImplicitlyAny.ts, 0, 5))
>undefined : Symbol(undefined)
@@ -0,0 +1,15 @@
=== tests/cases/compiler/objectLiteralPropertyImplicitlyAny.ts ===
const foo = Symbol.for("foo");
>foo : unique symbol
>Symbol.for("foo") : unique symbol
>Symbol.for : (key: string) => symbol
>Symbol : SymbolConstructor
>for : (key: string) => symbol
>"foo" : "foo"
const o = { [foo]: undefined };
>o : { [foo]: any; }
>{ [foo]: undefined } : { [foo]: undefined; }
>foo : unique symbol
>undefined : undefined
@@ -0,0 +1,5 @@
// @target: esnext
// @noImplicitAny: true
const foo = Symbol.for("foo");
const o = { [foo]: undefined };