adds error message for using value as type argument (#37359)

This addresses issue #28975
(https://github.com/microsoft/TypeScript/issues/28975).

When providing a value as a type argument, we can suggest a more specific
error message: "Did you mean to use typeof T?"

adds error message

WIP: Detect error

WIP: progress

updated tests

janky implementation

adds test coverage around literal types being unaffected

refactor out isIdentifierATypeArgument function

adds test case for type alias

adds test case for nested type arguments

fixes linting errors

merge master into branch to overwrite changes

changes value as type error message

This suggests 'typeof T' as a potential alternative when we give an error
about using value T as a type.

remove stale tests from old change

Co-authored-by: John Patterson <john@johnppatterson.com>
This commit is contained in:
Andrew Casey
2020-03-11 19:18:17 -07:00
committed by GitHub
parent 243186685b
commit 9e97b00ca1
7 changed files with 24 additions and 24 deletions

View File

@@ -2109,7 +2109,7 @@ namespace ts {
if (meaning & (SymbolFlags.Type & ~SymbolFlags.Namespace)) {
const symbol = resolveSymbol(resolveName(errorLocation, name, ~SymbolFlags.Type & SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false));
if (symbol && !(symbol.flags & SymbolFlags.Namespace)) {
error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here, unescapeLeadingUnderscores(name));
error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here_Did_you_mean_typeof_0, unescapeLeadingUnderscores(name));
return true;
}
}

View File

@@ -2763,7 +2763,7 @@
"category": "Error",
"code": 2748
},
"'{0}' refers to a value, but is being used as a type here.": {
"'{0}' refers to a value, but is being used as a type here. Did you mean 'typeof {0}'?": {
"category": "Error",
"code": 2749
},