From 82269551d7521a6e9d68480c507983186b619553 Mon Sep 17 00:00:00 2001 From: John Patterson Date: Wed, 24 Jul 2019 09:36:30 -0700 Subject: [PATCH 1/9] adds error message for using value as type argument 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 --- src/compiler/checker.ts | 11 ++++++++++- src/compiler/diagnosticMessages.json | 1 - ...arserAmbiguityWithBinaryOperator4.errors.txt | 8 ++++---- .../valueUsedAsTypeArgument.errors.txt | 16 ++++++++++++++++ .../reference/valueUsedAsTypeArgument.js | 12 ++++++++++++ .../reference/valueUsedAsTypeArgument.symbols | 17 +++++++++++++++++ .../reference/valueUsedAsTypeArgument.types | 16 ++++++++++++++++ tests/cases/compiler/valueUsedAsTypeArgument.ts | 7 +++++++ 8 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.errors.txt create mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.js create mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.symbols create mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.types create mode 100644 tests/cases/compiler/valueUsedAsTypeArgument.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8e1e826817be7..67ddc05196c74 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2001,7 +2001,16 @@ namespace ts { function checkAndReportErrorForUsingValueAsType(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean { 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)) { + const symbolIsValue = symbol && !(symbol.flags & SymbolFlags.Namespace); + const grandparentNode = errorLocation.parent.parent as NodeWithTypeArguments; + const isTypeArgument = grandparentNode && grandparentNode.typeArguments && grandparentNode.typeArguments.indexOf(errorLocation.parent as TypeNode) > -1; + + if (symbolIsValue && isTypeArgument){ + const unescapedName = unescapeLeadingUnderscores(name); + error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_argument_here_Did_you_mean_typeof_1, unescapedName, unescapedName); + return true; + } + else if (symbolIsValue) { error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here, unescapeLeadingUnderscores(name)); return true; } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index dede443895730..163103882c446 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2783,7 +2783,6 @@ "category": "Error", "code": 2781 }, - "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt index a94b60e5f996d..afe2c87da6555 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,9): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,11): error TS2749: 'b' refers to a value, but is being used as a type here. -tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,14): error TS2749: 'b' refers to a value, but is being used as a type here. +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,11): error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,14): error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? ==== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts (3 errors) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOpe ~~~~~~~~~~~~~~ !!! error TS2347: Untyped function calls may not accept type arguments. ~ -!!! error TS2749: 'b' refers to a value, but is being used as a type here. +!!! error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? ~ -!!! error TS2749: 'b' refers to a value, but is being used as a type here. +!!! error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? } \ No newline at end of file diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt new file mode 100644 index 0000000000000..597062e889815 --- /dev/null +++ b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt @@ -0,0 +1,16 @@ +tests/cases/compiler/valueUsedAsTypeArgument.ts(5,20): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? +tests/cases/compiler/valueUsedAsTypeArgument.ts(7,10): error TS2749: 'Something' refers to a value, but is being used as a type here. + + +==== tests/cases/compiler/valueUsedAsTypeArgument.ts (2 errors) ==== + type Foo = { items: T }; + + const Something = []; + + type SomeFoo = Foo; + ~~~~~~~~~ +!!! error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? + + const x: Something = []; + ~~~~~~~~~ +!!! error TS2749: 'Something' refers to a value, but is being used as a type here. \ No newline at end of file diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.js b/tests/baselines/reference/valueUsedAsTypeArgument.js new file mode 100644 index 0000000000000..70a2e5cd7f61f --- /dev/null +++ b/tests/baselines/reference/valueUsedAsTypeArgument.js @@ -0,0 +1,12 @@ +//// [valueUsedAsTypeArgument.ts] +type Foo = { items: T }; + +const Something = []; + +type SomeFoo = Foo; + +const x: Something = []; + +//// [valueUsedAsTypeArgument.js] +var Something = []; +var x = []; diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.symbols b/tests/baselines/reference/valueUsedAsTypeArgument.symbols new file mode 100644 index 0000000000000..4777212c97ff7 --- /dev/null +++ b/tests/baselines/reference/valueUsedAsTypeArgument.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/valueUsedAsTypeArgument.ts === +type Foo = { items: T }; +>Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) +>T : Symbol(T, Decl(valueUsedAsTypeArgument.ts, 0, 9)) +>items : Symbol(items, Decl(valueUsedAsTypeArgument.ts, 0, 15)) +>T : Symbol(T, Decl(valueUsedAsTypeArgument.ts, 0, 9)) + +const Something = []; +>Something : Symbol(Something, Decl(valueUsedAsTypeArgument.ts, 2, 5)) + +type SomeFoo = Foo; +>SomeFoo : Symbol(SomeFoo, Decl(valueUsedAsTypeArgument.ts, 2, 21)) +>Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) + +const x: Something = []; +>x : Symbol(x, Decl(valueUsedAsTypeArgument.ts, 6, 5)) + diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.types b/tests/baselines/reference/valueUsedAsTypeArgument.types new file mode 100644 index 0000000000000..9cb7c0df5d39c --- /dev/null +++ b/tests/baselines/reference/valueUsedAsTypeArgument.types @@ -0,0 +1,16 @@ +=== tests/cases/compiler/valueUsedAsTypeArgument.ts === +type Foo = { items: T }; +>Foo : Foo +>items : T + +const Something = []; +>Something : any[] +>[] : undefined[] + +type SomeFoo = Foo; +>SomeFoo : Foo + +const x: Something = []; +>x : any +>[] : undefined[] + diff --git a/tests/cases/compiler/valueUsedAsTypeArgument.ts b/tests/cases/compiler/valueUsedAsTypeArgument.ts new file mode 100644 index 0000000000000..9eade0009ee18 --- /dev/null +++ b/tests/cases/compiler/valueUsedAsTypeArgument.ts @@ -0,0 +1,7 @@ +type Foo = { items: T }; + +const Something = []; + +type SomeFoo = Foo; + +const x: Something = []; \ No newline at end of file From 075585cadbb6cc7228d42bd81e8c9506dc59d4a6 Mon Sep 17 00:00:00 2001 From: John Patterson Date: Wed, 24 Jul 2019 14:37:46 -0700 Subject: [PATCH 2/9] adds test coverage around literal types being unaffected --- .../reference/valueUsedAsTypeArgument.errors.txt | 5 ++++- tests/baselines/reference/valueUsedAsTypeArgument.js | 5 ++++- tests/baselines/reference/valueUsedAsTypeArgument.symbols | 8 ++++++++ tests/baselines/reference/valueUsedAsTypeArgument.types | 6 ++++++ tests/cases/compiler/valueUsedAsTypeArgument.ts | 5 ++++- 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt index 597062e889815..7c1ebb69f3ec3 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt +++ b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt @@ -13,4 +13,7 @@ tests/cases/compiler/valueUsedAsTypeArgument.ts(7,10): error TS2749: 'Something' const x: Something = []; ~~~~~~~~~ -!!! error TS2749: 'Something' refers to a value, but is being used as a type here. \ No newline at end of file +!!! error TS2749: 'Something' refers to a value, but is being used as a type here. + + type LiteralNumberFoo = Foo<1>; + type LiteralStringFoo = Foo<'test'>; \ No newline at end of file diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.js b/tests/baselines/reference/valueUsedAsTypeArgument.js index 70a2e5cd7f61f..b9e5fa0440e24 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.js +++ b/tests/baselines/reference/valueUsedAsTypeArgument.js @@ -5,7 +5,10 @@ const Something = []; type SomeFoo = Foo; -const x: Something = []; +const x: Something = []; + +type LiteralNumberFoo = Foo<1>; +type LiteralStringFoo = Foo<'test'>; //// [valueUsedAsTypeArgument.js] var Something = []; diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.symbols b/tests/baselines/reference/valueUsedAsTypeArgument.symbols index 4777212c97ff7..5db1bff32e56c 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.symbols +++ b/tests/baselines/reference/valueUsedAsTypeArgument.symbols @@ -15,3 +15,11 @@ type SomeFoo = Foo; const x: Something = []; >x : Symbol(x, Decl(valueUsedAsTypeArgument.ts, 6, 5)) +type LiteralNumberFoo = Foo<1>; +>LiteralNumberFoo : Symbol(LiteralNumberFoo, Decl(valueUsedAsTypeArgument.ts, 6, 24)) +>Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) + +type LiteralStringFoo = Foo<'test'>; +>LiteralStringFoo : Symbol(LiteralStringFoo, Decl(valueUsedAsTypeArgument.ts, 8, 31)) +>Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) + diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.types b/tests/baselines/reference/valueUsedAsTypeArgument.types index 9cb7c0df5d39c..29153b0e6d13c 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.types +++ b/tests/baselines/reference/valueUsedAsTypeArgument.types @@ -14,3 +14,9 @@ const x: Something = []; >x : any >[] : undefined[] +type LiteralNumberFoo = Foo<1>; +>LiteralNumberFoo : Foo<1> + +type LiteralStringFoo = Foo<'test'>; +>LiteralStringFoo : Foo<"test"> + diff --git a/tests/cases/compiler/valueUsedAsTypeArgument.ts b/tests/cases/compiler/valueUsedAsTypeArgument.ts index 9eade0009ee18..8b48a01b379af 100644 --- a/tests/cases/compiler/valueUsedAsTypeArgument.ts +++ b/tests/cases/compiler/valueUsedAsTypeArgument.ts @@ -4,4 +4,7 @@ const Something = []; type SomeFoo = Foo; -const x: Something = []; \ No newline at end of file +const x: Something = []; + +type LiteralNumberFoo = Foo<1>; +type LiteralStringFoo = Foo<'test'>; \ No newline at end of file From a1ee287a36d739aa3059dd50c8187b8e204601bc Mon Sep 17 00:00:00 2001 From: John Patterson Date: Wed, 24 Jul 2019 15:19:22 -0700 Subject: [PATCH 3/9] refactor out isIdentifierATypeArgument function --- src/compiler/checker.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 67ddc05196c74..f9eecb5cac7ca 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2002,10 +2002,8 @@ namespace ts { if (meaning & (SymbolFlags.Type & ~SymbolFlags.Namespace)) { const symbol = resolveSymbol(resolveName(errorLocation, name, ~SymbolFlags.Type & SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false)); const symbolIsValue = symbol && !(symbol.flags & SymbolFlags.Namespace); - const grandparentNode = errorLocation.parent.parent as NodeWithTypeArguments; - const isTypeArgument = grandparentNode && grandparentNode.typeArguments && grandparentNode.typeArguments.indexOf(errorLocation.parent as TypeNode) > -1; - if (symbolIsValue && isTypeArgument){ + if (symbolIsValue && isIdentifierATypeArgument(errorLocation)){ const unescapedName = unescapeLeadingUnderscores(name); error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_argument_here_Did_you_mean_typeof_1, unescapedName, unescapedName); return true; @@ -2017,6 +2015,16 @@ namespace ts { } return false; } + + function isIdentifierATypeArgument(node: Node): boolean { + const grandparentNode = node.parent.parent as NodeWithTypeArguments; + if (grandparentNode && grandparentNode.typeArguments) { + const parent = node.parent as TypeNode; + return grandparentNode.typeArguments.indexOf(parent) > -1; + } + + return false; + } function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean { if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) { From 36433e9185669fa52dd0469b33c3c909a940880f Mon Sep 17 00:00:00 2001 From: John Patterson Date: Wed, 24 Jul 2019 15:29:58 -0700 Subject: [PATCH 4/9] adds test case for type alias --- .../reference/valueUsedAsTypeArgument.errors.txt | 8 ++++++-- tests/baselines/reference/valueUsedAsTypeArgument.js | 1 + .../baselines/reference/valueUsedAsTypeArgument.symbols | 9 ++++++--- tests/baselines/reference/valueUsedAsTypeArgument.types | 3 +++ tests/cases/compiler/valueUsedAsTypeArgument.ts | 1 + 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt index 7c1ebb69f3ec3..eb59443e7daa9 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt +++ b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt @@ -1,8 +1,9 @@ tests/cases/compiler/valueUsedAsTypeArgument.ts(5,20): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? -tests/cases/compiler/valueUsedAsTypeArgument.ts(7,10): error TS2749: 'Something' refers to a value, but is being used as a type here. +tests/cases/compiler/valueUsedAsTypeArgument.ts(6,16): error TS2749: 'Something' refers to a value, but is being used as a type here. +tests/cases/compiler/valueUsedAsTypeArgument.ts(8,10): error TS2749: 'Something' refers to a value, but is being used as a type here. -==== tests/cases/compiler/valueUsedAsTypeArgument.ts (2 errors) ==== +==== tests/cases/compiler/valueUsedAsTypeArgument.ts (3 errors) ==== type Foo = { items: T }; const Something = []; @@ -10,6 +11,9 @@ tests/cases/compiler/valueUsedAsTypeArgument.ts(7,10): error TS2749: 'Something' type SomeFoo = Foo; ~~~~~~~~~ !!! error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? + type SomeBar = Something; + ~~~~~~~~~ +!!! error TS2749: 'Something' refers to a value, but is being used as a type here. const x: Something = []; ~~~~~~~~~ diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.js b/tests/baselines/reference/valueUsedAsTypeArgument.js index b9e5fa0440e24..ae72f0c429b87 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.js +++ b/tests/baselines/reference/valueUsedAsTypeArgument.js @@ -4,6 +4,7 @@ type Foo = { items: T }; const Something = []; type SomeFoo = Foo; +type SomeBar = Something; const x: Something = []; diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.symbols b/tests/baselines/reference/valueUsedAsTypeArgument.symbols index 5db1bff32e56c..aeb93a84b591d 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.symbols +++ b/tests/baselines/reference/valueUsedAsTypeArgument.symbols @@ -12,14 +12,17 @@ type SomeFoo = Foo; >SomeFoo : Symbol(SomeFoo, Decl(valueUsedAsTypeArgument.ts, 2, 21)) >Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) +type SomeBar = Something; +>SomeBar : Symbol(SomeBar, Decl(valueUsedAsTypeArgument.ts, 4, 30)) + const x: Something = []; ->x : Symbol(x, Decl(valueUsedAsTypeArgument.ts, 6, 5)) +>x : Symbol(x, Decl(valueUsedAsTypeArgument.ts, 7, 5)) type LiteralNumberFoo = Foo<1>; ->LiteralNumberFoo : Symbol(LiteralNumberFoo, Decl(valueUsedAsTypeArgument.ts, 6, 24)) +>LiteralNumberFoo : Symbol(LiteralNumberFoo, Decl(valueUsedAsTypeArgument.ts, 7, 24)) >Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) type LiteralStringFoo = Foo<'test'>; ->LiteralStringFoo : Symbol(LiteralStringFoo, Decl(valueUsedAsTypeArgument.ts, 8, 31)) +>LiteralStringFoo : Symbol(LiteralStringFoo, Decl(valueUsedAsTypeArgument.ts, 9, 31)) >Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.types b/tests/baselines/reference/valueUsedAsTypeArgument.types index 29153b0e6d13c..2a08177fb8641 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.types +++ b/tests/baselines/reference/valueUsedAsTypeArgument.types @@ -10,6 +10,9 @@ const Something = []; type SomeFoo = Foo; >SomeFoo : Foo +type SomeBar = Something; +>SomeBar : any + const x: Something = []; >x : any >[] : undefined[] diff --git a/tests/cases/compiler/valueUsedAsTypeArgument.ts b/tests/cases/compiler/valueUsedAsTypeArgument.ts index 8b48a01b379af..85959443fc629 100644 --- a/tests/cases/compiler/valueUsedAsTypeArgument.ts +++ b/tests/cases/compiler/valueUsedAsTypeArgument.ts @@ -3,6 +3,7 @@ type Foo = { items: T }; const Something = []; type SomeFoo = Foo; +type SomeBar = Something; const x: Something = []; From 36153247d74e94bc914954a5a8fedbb30ed121ce Mon Sep 17 00:00:00 2001 From: John Patterson Date: Wed, 24 Jul 2019 15:46:22 -0700 Subject: [PATCH 5/9] adds test case for nested type arguments --- .../valueUsedAsTypeArgument.errors.txt | 22 ++++++++++++--- .../reference/valueUsedAsTypeArgument.js | 12 +++++++++ .../reference/valueUsedAsTypeArgument.symbols | 27 ++++++++++++++----- .../reference/valueUsedAsTypeArgument.types | 12 +++++++++ .../cases/compiler/valueUsedAsTypeArgument.ts | 11 ++++++++ 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt index eb59443e7daa9..411ac5181431e 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt +++ b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt @@ -1,23 +1,37 @@ -tests/cases/compiler/valueUsedAsTypeArgument.ts(5,20): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? -tests/cases/compiler/valueUsedAsTypeArgument.ts(6,16): error TS2749: 'Something' refers to a value, but is being used as a type here. -tests/cases/compiler/valueUsedAsTypeArgument.ts(8,10): error TS2749: 'Something' refers to a value, but is being used as a type here. +tests/cases/compiler/valueUsedAsTypeArgument.ts(7,20): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? +tests/cases/compiler/valueUsedAsTypeArgument.ts(10,16): error TS2749: 'Something' refers to a value, but is being used as a type here. +tests/cases/compiler/valueUsedAsTypeArgument.ts(13,28): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? +tests/cases/compiler/valueUsedAsTypeArgument.ts(16,10): error TS2749: 'Something' refers to a value, but is being used as a type here. -==== tests/cases/compiler/valueUsedAsTypeArgument.ts (3 errors) ==== +==== tests/cases/compiler/valueUsedAsTypeArgument.ts (4 errors) ==== type Foo = { items: T }; + type Other = {}; const Something = []; + // Type argument, should show new error type SomeFoo = Foo; ~~~~~~~~~ !!! error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? + + // Type alias type SomeBar = Something; ~~~~~~~~~ !!! error TS2749: 'Something' refers to a value, but is being used as a type here. + // Nested type arguments, should show new error + type SomeOther = Other>; + ~~~~~~~~~ +!!! error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? + + // Misuse of value const x: Something = []; ~~~~~~~~~ !!! error TS2749: 'Something' refers to a value, but is being used as a type here. + // Numeric literal type type LiteralNumberFoo = Foo<1>; + + // String literal type type LiteralStringFoo = Foo<'test'>; \ No newline at end of file diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.js b/tests/baselines/reference/valueUsedAsTypeArgument.js index ae72f0c429b87..785686b9b7e07 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.js +++ b/tests/baselines/reference/valueUsedAsTypeArgument.js @@ -1,16 +1,28 @@ //// [valueUsedAsTypeArgument.ts] type Foo = { items: T }; +type Other = {}; const Something = []; +// Type argument, should show new error type SomeFoo = Foo; + +// Type alias type SomeBar = Something; +// Nested type arguments, should show new error +type SomeOther = Other>; + +// Misuse of value const x: Something = []; +// Numeric literal type type LiteralNumberFoo = Foo<1>; + +// String literal type type LiteralStringFoo = Foo<'test'>; //// [valueUsedAsTypeArgument.js] var Something = []; +// Misuse of value var x = []; diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.symbols b/tests/baselines/reference/valueUsedAsTypeArgument.symbols index aeb93a84b591d..d817df667c24b 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.symbols +++ b/tests/baselines/reference/valueUsedAsTypeArgument.symbols @@ -5,24 +5,39 @@ type Foo = { items: T }; >items : Symbol(items, Decl(valueUsedAsTypeArgument.ts, 0, 15)) >T : Symbol(T, Decl(valueUsedAsTypeArgument.ts, 0, 9)) +type Other = {}; +>Other : Symbol(Other, Decl(valueUsedAsTypeArgument.ts, 0, 27)) +>U : Symbol(U, Decl(valueUsedAsTypeArgument.ts, 1, 11)) + const Something = []; ->Something : Symbol(Something, Decl(valueUsedAsTypeArgument.ts, 2, 5)) +>Something : Symbol(Something, Decl(valueUsedAsTypeArgument.ts, 3, 5)) +// Type argument, should show new error type SomeFoo = Foo; ->SomeFoo : Symbol(SomeFoo, Decl(valueUsedAsTypeArgument.ts, 2, 21)) +>SomeFoo : Symbol(SomeFoo, Decl(valueUsedAsTypeArgument.ts, 3, 21)) >Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) +// Type alias type SomeBar = Something; ->SomeBar : Symbol(SomeBar, Decl(valueUsedAsTypeArgument.ts, 4, 30)) +>SomeBar : Symbol(SomeBar, Decl(valueUsedAsTypeArgument.ts, 6, 30)) + +// Nested type arguments, should show new error +type SomeOther = Other>; +>SomeOther : Symbol(SomeOther, Decl(valueUsedAsTypeArgument.ts, 9, 25)) +>Other : Symbol(Other, Decl(valueUsedAsTypeArgument.ts, 0, 27)) +>Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) +// Misuse of value const x: Something = []; ->x : Symbol(x, Decl(valueUsedAsTypeArgument.ts, 7, 5)) +>x : Symbol(x, Decl(valueUsedAsTypeArgument.ts, 15, 5)) +// Numeric literal type type LiteralNumberFoo = Foo<1>; ->LiteralNumberFoo : Symbol(LiteralNumberFoo, Decl(valueUsedAsTypeArgument.ts, 7, 24)) +>LiteralNumberFoo : Symbol(LiteralNumberFoo, Decl(valueUsedAsTypeArgument.ts, 15, 24)) >Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) +// String literal type type LiteralStringFoo = Foo<'test'>; ->LiteralStringFoo : Symbol(LiteralStringFoo, Decl(valueUsedAsTypeArgument.ts, 9, 31)) +>LiteralStringFoo : Symbol(LiteralStringFoo, Decl(valueUsedAsTypeArgument.ts, 18, 31)) >Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.types b/tests/baselines/reference/valueUsedAsTypeArgument.types index 2a08177fb8641..6363c0e7f64f2 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.types +++ b/tests/baselines/reference/valueUsedAsTypeArgument.types @@ -3,23 +3,35 @@ type Foo = { items: T }; >Foo : Foo >items : T +type Other = {}; +>Other : Other + const Something = []; >Something : any[] >[] : undefined[] +// Type argument, should show new error type SomeFoo = Foo; >SomeFoo : Foo +// Type alias type SomeBar = Something; >SomeBar : any +// Nested type arguments, should show new error +type SomeOther = Other>; +>SomeOther : Other> + +// Misuse of value const x: Something = []; >x : any >[] : undefined[] +// Numeric literal type type LiteralNumberFoo = Foo<1>; >LiteralNumberFoo : Foo<1> +// String literal type type LiteralStringFoo = Foo<'test'>; >LiteralStringFoo : Foo<"test"> diff --git a/tests/cases/compiler/valueUsedAsTypeArgument.ts b/tests/cases/compiler/valueUsedAsTypeArgument.ts index 85959443fc629..4f0a39d353b9d 100644 --- a/tests/cases/compiler/valueUsedAsTypeArgument.ts +++ b/tests/cases/compiler/valueUsedAsTypeArgument.ts @@ -1,11 +1,22 @@ type Foo = { items: T }; +type Other = {}; const Something = []; +// Type argument, should show new error type SomeFoo = Foo; + +// Type alias type SomeBar = Something; +// Nested type arguments, should show new error +type SomeOther = Other>; + +// Misuse of value const x: Something = []; +// Numeric literal type type LiteralNumberFoo = Foo<1>; + +// String literal type type LiteralStringFoo = Foo<'test'>; \ No newline at end of file From ace16fb8c365fd2327f65c14b5d912f481dde96e Mon Sep 17 00:00:00 2001 From: John Patterson Date: Wed, 24 Jul 2019 16:05:04 -0700 Subject: [PATCH 6/9] fixes linting errors --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f9eecb5cac7ca..025e52cad3e14 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2003,7 +2003,7 @@ namespace ts { const symbol = resolveSymbol(resolveName(errorLocation, name, ~SymbolFlags.Type & SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false)); const symbolIsValue = symbol && !(symbol.flags & SymbolFlags.Namespace); - if (symbolIsValue && isIdentifierATypeArgument(errorLocation)){ + if (symbolIsValue && isIdentifierATypeArgument(errorLocation)) { const unescapedName = unescapeLeadingUnderscores(name); error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_argument_here_Did_you_mean_typeof_1, unescapedName, unescapedName); return true; @@ -2015,7 +2015,7 @@ namespace ts { } return false; } - + function isIdentifierATypeArgument(node: Node): boolean { const grandparentNode = node.parent.parent as NodeWithTypeArguments; if (grandparentNode && grandparentNode.typeArguments) { From 2bff306e1c654a056d0283271b7c74635939a3c8 Mon Sep 17 00:00:00 2001 From: John Patterson Date: Fri, 11 Oct 2019 20:40:06 -0700 Subject: [PATCH 7/9] merge master into branch to overwrite changes --- src/compiler/checker.ts | 19 +------------------ src/compiler/diagnosticMessages.json | 1 + ...serAmbiguityWithBinaryOperator4.errors.txt | 8 ++++---- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 025e52cad3e14..8e1e826817be7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2001,14 +2001,7 @@ namespace ts { function checkAndReportErrorForUsingValueAsType(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean { if (meaning & (SymbolFlags.Type & ~SymbolFlags.Namespace)) { const symbol = resolveSymbol(resolveName(errorLocation, name, ~SymbolFlags.Type & SymbolFlags.Value, /*nameNotFoundMessage*/undefined, /*nameArg*/ undefined, /*isUse*/ false)); - const symbolIsValue = symbol && !(symbol.flags & SymbolFlags.Namespace); - - if (symbolIsValue && isIdentifierATypeArgument(errorLocation)) { - const unescapedName = unescapeLeadingUnderscores(name); - error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_argument_here_Did_you_mean_typeof_1, unescapedName, unescapedName); - return true; - } - else if (symbolIsValue) { + if (symbol && !(symbol.flags & SymbolFlags.Namespace)) { error(errorLocation, Diagnostics._0_refers_to_a_value_but_is_being_used_as_a_type_here, unescapeLeadingUnderscores(name)); return true; } @@ -2016,16 +2009,6 @@ namespace ts { return false; } - function isIdentifierATypeArgument(node: Node): boolean { - const grandparentNode = node.parent.parent as NodeWithTypeArguments; - if (grandparentNode && grandparentNode.typeArguments) { - const parent = node.parent as TypeNode; - return grandparentNode.typeArguments.indexOf(parent) > -1; - } - - return false; - } - function checkAndReportErrorForUsingTypeAsValue(errorLocation: Node, name: __String, meaning: SymbolFlags): boolean { if (meaning & (SymbolFlags.Value & ~SymbolFlags.NamespaceModule)) { if (name === "any" || name === "string" || name === "number" || name === "boolean" || name === "never") { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 163103882c446..dede443895730 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2783,6 +2783,7 @@ "category": "Error", "code": 2781 }, + "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", "code": 4000 diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt index afe2c87da6555..a94b60e5f996d 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,9): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,11): error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? -tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,14): error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,11): error TS2749: 'b' refers to a value, but is being used as a type here. +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,14): error TS2749: 'b' refers to a value, but is being used as a type here. ==== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts (3 errors) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOpe ~~~~~~~~~~~~~~ !!! error TS2347: Untyped function calls may not accept type arguments. ~ -!!! error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? +!!! error TS2749: 'b' refers to a value, but is being used as a type here. ~ -!!! error TS2774: 'b' refers to a value, but is being used as a type argument here. Did you mean 'typeof b'? +!!! error TS2749: 'b' refers to a value, but is being used as a type here. } \ No newline at end of file From b0e7a7f7cbdbaa9d2ae6b4da494765ec95da3e47 Mon Sep 17 00:00:00 2001 From: John Patterson Date: Fri, 11 Oct 2019 20:50:58 -0700 Subject: [PATCH 8/9] 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. --- src/compiler/diagnosticMessages.json | 2 +- ...owImportClausesToMergeWithTypes.errors.txt | 4 ++-- .../baselines/reference/intrinsics.errors.txt | 4 ++-- ...eNongenericInstantiationAttempt.errors.txt | 4 ++-- ...serAmbiguityWithBinaryOperator4.errors.txt | 8 ++++---- .../reference/typeAssertions.errors.txt | 8 ++++---- .../typeGuardFunctionErrors.errors.txt | 20 +++++++++---------- .../valueUsedAsTypeArgument.errors.txt | 8 ++++---- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index dede443895730..949c7288c4415 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -2651,7 +2651,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 }, diff --git a/tests/baselines/reference/allowImportClausesToMergeWithTypes.errors.txt b/tests/baselines/reference/allowImportClausesToMergeWithTypes.errors.txt index 8c4f995531047..63cb28ea7d626 100644 --- a/tests/baselines/reference/allowImportClausesToMergeWithTypes.errors.txt +++ b/tests/baselines/reference/allowImportClausesToMergeWithTypes.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/index.ts(4,1): error TS2693: 'zzz' only refers to a type, but is being used as a value here. -tests/cases/compiler/index.ts(9,10): error TS2749: 'originalZZZ' refers to a value, but is being used as a type here. +tests/cases/compiler/index.ts(9,10): error TS2749: 'originalZZZ' refers to a value, but is being used as a type here. Did you mean 'typeof originalZZZ'? ==== tests/cases/compiler/b.ts (0 errors) ==== @@ -31,4 +31,4 @@ tests/cases/compiler/index.ts(9,10): error TS2749: 'originalZZZ' refers to a val const y: originalZZZ = x; ~~~~~~~~~~~ -!!! error TS2749: 'originalZZZ' refers to a value, but is being used as a type here. \ No newline at end of file +!!! error TS2749: 'originalZZZ' refers to a value, but is being used as a type here. Did you mean 'typeof originalZZZ'? \ No newline at end of file diff --git a/tests/baselines/reference/intrinsics.errors.txt b/tests/baselines/reference/intrinsics.errors.txt index 13d61dacbcf97..ef86f505ed27e 100644 --- a/tests/baselines/reference/intrinsics.errors.txt +++ b/tests/baselines/reference/intrinsics.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/intrinsics.ts(1,21): error TS2749: 'hasOwnProperty' refers to a value, but is being used as a type here. +tests/cases/compiler/intrinsics.ts(1,21): error TS2749: 'hasOwnProperty' refers to a value, but is being used as a type here. Did you mean 'typeof hasOwnProperty'? tests/cases/compiler/intrinsics.ts(1,21): error TS4025: Exported variable 'hasOwnProperty' has or is using private name 'hasOwnProperty'. tests/cases/compiler/intrinsics.ts(10,1): error TS2304: Cannot find name '__proto__'. @@ -6,7 +6,7 @@ tests/cases/compiler/intrinsics.ts(10,1): error TS2304: Cannot find name '__prot ==== tests/cases/compiler/intrinsics.ts (3 errors) ==== var hasOwnProperty: hasOwnProperty; // Error ~~~~~~~~~~~~~~ -!!! error TS2749: 'hasOwnProperty' refers to a value, but is being used as a type here. +!!! error TS2749: 'hasOwnProperty' refers to a value, but is being used as a type here. Did you mean 'typeof hasOwnProperty'? ~~~~~~~~~~~~~~ !!! error TS4025: Exported variable 'hasOwnProperty' has or is using private name 'hasOwnProperty'. diff --git a/tests/baselines/reference/jsdocTypeNongenericInstantiationAttempt.errors.txt b/tests/baselines/reference/jsdocTypeNongenericInstantiationAttempt.errors.txt index b3298f137f14f..d9a2bf8039fa2 100644 --- a/tests/baselines/reference/jsdocTypeNongenericInstantiationAttempt.errors.txt +++ b/tests/baselines/reference/jsdocTypeNongenericInstantiationAttempt.errors.txt @@ -5,7 +5,7 @@ tests/cases/compiler/index4.js(2,19): error TS2315: Type 'Function' is not gener tests/cases/compiler/index5.js(2,19): error TS2315: Type 'String' is not generic. tests/cases/compiler/index6.js(2,19): error TS2315: Type 'Number' is not generic. tests/cases/compiler/index7.js(2,19): error TS2315: Type 'Object' is not generic. -tests/cases/compiler/index8.js(4,12): error TS2749: 'fn' refers to a value, but is being used as a type here. +tests/cases/compiler/index8.js(4,12): error TS2749: 'fn' refers to a value, but is being used as a type here. Did you mean 'typeof fn'? tests/cases/compiler/index8.js(4,15): error TS2304: Cannot find name 'T'. @@ -90,7 +90,7 @@ tests/cases/compiler/index8.js(4,15): error TS2304: Cannot find name 'T'. /** * @param {fn} somebody ~~ -!!! error TS2749: 'fn' refers to a value, but is being used as a type here. +!!! error TS2749: 'fn' refers to a value, but is being used as a type here. Did you mean 'typeof fn'? ~ !!! error TS2304: Cannot find name 'T'. */ diff --git a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt index a94b60e5f996d..af2167f777f0f 100644 --- a/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt +++ b/tests/baselines/reference/parserAmbiguityWithBinaryOperator4.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,9): error TS2347: Untyped function calls may not accept type arguments. -tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,11): error TS2749: 'b' refers to a value, but is being used as a type here. -tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,14): error TS2749: 'b' refers to a value, but is being used as a type here. +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,11): error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? +tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts(3,14): error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? ==== tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOperator4.ts (3 errors) ==== @@ -10,7 +10,7 @@ tests/cases/conformance/parser/ecmascript5/Generics/parserAmbiguityWithBinaryOpe ~~~~~~~~~~~~~~ !!! error TS2347: Untyped function calls may not accept type arguments. ~ -!!! error TS2749: 'b' refers to a value, but is being used as a type here. +!!! error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? ~ -!!! error TS2749: 'b' refers to a value, but is being used as a type here. +!!! error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? } \ No newline at end of file diff --git a/tests/baselines/reference/typeAssertions.errors.txt b/tests/baselines/reference/typeAssertions.errors.txt index ef9a23b8d8ae4..9d10ec17fe95d 100644 --- a/tests/baselines/reference/typeAssertions.errors.txt +++ b/tests/baselines/reference/typeAssertions.errors.txt @@ -7,7 +7,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): err Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2352: Conversion of type 'SomeBase' to type 'SomeOther' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,5): error TS2749: 'numOrStr' refers to a value, but is being used as a type here. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,5): error TS2749: 'numOrStr' refers to a value, but is being used as a type here. Did you mean 'typeof numOrStr'? tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,14): error TS1005: '>' expected. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,14): error TS2304: Cannot find name 'is'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,17): error TS1005: ')' expected. @@ -15,7 +15,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,17): err tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,48): error TS1005: ';' expected. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(45,2): error TS2322: Type 'string | number' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. -tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,32): error TS2749: 'numOrStr' refers to a value, but is being used as a type here. +tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,32): error TS2749: 'numOrStr' refers to a value, but is being used as a type here. Did you mean 'typeof numOrStr'? tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,41): error TS1005: ')' expected. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,41): error TS2304: Cannot find name 'is'. tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,44): error TS1005: ';' expected. @@ -86,7 +86,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): err var str: string; if((numOrStr === undefined)) { // Error ~~~~~~~~ -!!! error TS2749: 'numOrStr' refers to a value, but is being used as a type here. +!!! error TS2749: 'numOrStr' refers to a value, but is being used as a type here. Did you mean 'typeof numOrStr'? ~~ !!! error TS1005: '>' expected. ~~ @@ -105,7 +105,7 @@ tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): err if((numOrStr === undefined) as numOrStr is string) { // Error ~~~~~~~~ -!!! error TS2749: 'numOrStr' refers to a value, but is being used as a type here. +!!! error TS2749: 'numOrStr' refers to a value, but is being used as a type here. Did you mean 'typeof numOrStr'? ~~ !!! error TS1005: ')' expected. ~~ diff --git a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt index 6f24585a85f2b..2f3e7eb1862ed 100644 --- a/tests/baselines/reference/typeGuardFunctionErrors.errors.txt +++ b/tests/baselines/reference/typeGuardFunctionErrors.errors.txt @@ -1,10 +1,10 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(1,7): error TS2300: Duplicate identifier 'A'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(14,5): error TS2322: Type '""' is not assignable to type 'boolean'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(17,55): error TS2749: 'x' refers to a value, but is being used as a type here. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(17,55): error TS2749: 'x' refers to a value, but is being used as a type here. Did you mean 'typeof x'? tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(17,57): error TS1144: '{' or ';' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(17,60): error TS1005: ';' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(17,62): error TS1005: ';' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(21,33): error TS2749: 'x' refers to a value, but is being used as a type here. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(21,33): error TS2749: 'x' refers to a value, but is being used as a type here. Did you mean 'typeof x'? tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(25,33): error TS1225: Cannot find parameter 'x'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(29,10): error TS2391: Function implementation is missing or not immediately following the declaration. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(30,5): error TS1131: Property or signature expected. @@ -28,14 +28,14 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(84,1): Type predicate 'p2 is A' is not assignable to 'p1 is A'. Parameter 'p2' is not in the same position as parameter 'p1'. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(90,1): error TS2322: Type '(p1: any, p2: any, p3: any) => p1 is A' is not assignable to type '(p1: any, p2: any) => p1 is A'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,9): error TS2749: 'b' refers to a value, but is being used as a type here. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,9): error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,11): error TS1005: ',' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,14): error TS1005: ',' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(95,14): error TS2300: Duplicate identifier 'A'. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,16): error TS2749: 'b' refers to a value, but is being used as a type here. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,16): error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,18): error TS1005: ',' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(96,21): error TS1005: ',' expected. -tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,20): error TS2749: 'b' refers to a value, but is being used as a type here. +tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,20): error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,22): error TS1144: '{' or ';' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,25): error TS1005: ';' expected. tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(97,27): error TS1005: ';' expected. @@ -91,7 +91,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54 function hasTypeGuardTypeInsideTypeGuardType(x): x is x is A { ~ -!!! error TS2749: 'x' refers to a value, but is being used as a type here. +!!! error TS2749: 'x' refers to a value, but is being used as a type here. Did you mean 'typeof x'? ~~ !!! error TS1144: '{' or ';' expected. ~ @@ -103,7 +103,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54 function hasMissingIsKeyword(): x { ~ -!!! error TS2749: 'x' refers to a value, but is being used as a type here. +!!! error TS2749: 'x' refers to a value, but is being used as a type here. Did you mean 'typeof x'? return true; } @@ -222,7 +222,7 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54 // Type predicates in non-return type positions var b1: b is A; ~ -!!! error TS2749: 'b' refers to a value, but is being used as a type here. +!!! error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? ~~ !!! error TS1005: ',' expected. ~ @@ -231,14 +231,14 @@ tests/cases/conformance/expressions/typeGuards/typeGuardFunctionErrors.ts(166,54 !!! error TS2300: Duplicate identifier 'A'. function b2(a: b is A) {}; ~ -!!! error TS2749: 'b' refers to a value, but is being used as a type here. +!!! error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? ~~ !!! error TS1005: ',' expected. ~ !!! error TS1005: ',' expected. function b3(): A | b is A { ~ -!!! error TS2749: 'b' refers to a value, but is being used as a type here. +!!! error TS2749: 'b' refers to a value, but is being used as a type here. Did you mean 'typeof b'? ~~ !!! error TS1144: '{' or ';' expected. ~ diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt index 411ac5181431e..5858f287f90d6 100644 --- a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt +++ b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/valueUsedAsTypeArgument.ts(7,20): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? -tests/cases/compiler/valueUsedAsTypeArgument.ts(10,16): error TS2749: 'Something' refers to a value, but is being used as a type here. +tests/cases/compiler/valueUsedAsTypeArgument.ts(10,16): error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? tests/cases/compiler/valueUsedAsTypeArgument.ts(13,28): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? -tests/cases/compiler/valueUsedAsTypeArgument.ts(16,10): error TS2749: 'Something' refers to a value, but is being used as a type here. +tests/cases/compiler/valueUsedAsTypeArgument.ts(16,10): error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? ==== tests/cases/compiler/valueUsedAsTypeArgument.ts (4 errors) ==== @@ -18,7 +18,7 @@ tests/cases/compiler/valueUsedAsTypeArgument.ts(16,10): error TS2749: 'Something // Type alias type SomeBar = Something; ~~~~~~~~~ -!!! error TS2749: 'Something' refers to a value, but is being used as a type here. +!!! error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? // Nested type arguments, should show new error type SomeOther = Other>; @@ -28,7 +28,7 @@ tests/cases/compiler/valueUsedAsTypeArgument.ts(16,10): error TS2749: 'Something // Misuse of value const x: Something = []; ~~~~~~~~~ -!!! error TS2749: 'Something' refers to a value, but is being used as a type here. +!!! error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? // Numeric literal type type LiteralNumberFoo = Foo<1>; From d1b4130be9ae93982cb19841e556837f0122aea5 Mon Sep 17 00:00:00 2001 From: John Patterson Date: Fri, 11 Oct 2019 20:53:52 -0700 Subject: [PATCH 9/9] remove stale tests from old change --- .../valueUsedAsTypeArgument.errors.txt | 37 ---------------- .../reference/valueUsedAsTypeArgument.js | 28 ------------ .../reference/valueUsedAsTypeArgument.symbols | 43 ------------------- .../reference/valueUsedAsTypeArgument.types | 37 ---------------- .../cases/compiler/valueUsedAsTypeArgument.ts | 22 ---------- 5 files changed, 167 deletions(-) delete mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.errors.txt delete mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.js delete mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.symbols delete mode 100644 tests/baselines/reference/valueUsedAsTypeArgument.types delete mode 100644 tests/cases/compiler/valueUsedAsTypeArgument.ts diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt b/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt deleted file mode 100644 index 5858f287f90d6..0000000000000 --- a/tests/baselines/reference/valueUsedAsTypeArgument.errors.txt +++ /dev/null @@ -1,37 +0,0 @@ -tests/cases/compiler/valueUsedAsTypeArgument.ts(7,20): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? -tests/cases/compiler/valueUsedAsTypeArgument.ts(10,16): error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? -tests/cases/compiler/valueUsedAsTypeArgument.ts(13,28): error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? -tests/cases/compiler/valueUsedAsTypeArgument.ts(16,10): error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? - - -==== tests/cases/compiler/valueUsedAsTypeArgument.ts (4 errors) ==== - type Foo = { items: T }; - type Other = {}; - - const Something = []; - - // Type argument, should show new error - type SomeFoo = Foo; - ~~~~~~~~~ -!!! error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? - - // Type alias - type SomeBar = Something; - ~~~~~~~~~ -!!! error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? - - // Nested type arguments, should show new error - type SomeOther = Other>; - ~~~~~~~~~ -!!! error TS2774: 'Something' refers to a value, but is being used as a type argument here. Did you mean 'typeof Something'? - - // Misuse of value - const x: Something = []; - ~~~~~~~~~ -!!! error TS2749: 'Something' refers to a value, but is being used as a type here. Did you mean 'typeof Something'? - - // Numeric literal type - type LiteralNumberFoo = Foo<1>; - - // String literal type - type LiteralStringFoo = Foo<'test'>; \ No newline at end of file diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.js b/tests/baselines/reference/valueUsedAsTypeArgument.js deleted file mode 100644 index 785686b9b7e07..0000000000000 --- a/tests/baselines/reference/valueUsedAsTypeArgument.js +++ /dev/null @@ -1,28 +0,0 @@ -//// [valueUsedAsTypeArgument.ts] -type Foo = { items: T }; -type Other = {}; - -const Something = []; - -// Type argument, should show new error -type SomeFoo = Foo; - -// Type alias -type SomeBar = Something; - -// Nested type arguments, should show new error -type SomeOther = Other>; - -// Misuse of value -const x: Something = []; - -// Numeric literal type -type LiteralNumberFoo = Foo<1>; - -// String literal type -type LiteralStringFoo = Foo<'test'>; - -//// [valueUsedAsTypeArgument.js] -var Something = []; -// Misuse of value -var x = []; diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.symbols b/tests/baselines/reference/valueUsedAsTypeArgument.symbols deleted file mode 100644 index d817df667c24b..0000000000000 --- a/tests/baselines/reference/valueUsedAsTypeArgument.symbols +++ /dev/null @@ -1,43 +0,0 @@ -=== tests/cases/compiler/valueUsedAsTypeArgument.ts === -type Foo = { items: T }; ->Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) ->T : Symbol(T, Decl(valueUsedAsTypeArgument.ts, 0, 9)) ->items : Symbol(items, Decl(valueUsedAsTypeArgument.ts, 0, 15)) ->T : Symbol(T, Decl(valueUsedAsTypeArgument.ts, 0, 9)) - -type Other = {}; ->Other : Symbol(Other, Decl(valueUsedAsTypeArgument.ts, 0, 27)) ->U : Symbol(U, Decl(valueUsedAsTypeArgument.ts, 1, 11)) - -const Something = []; ->Something : Symbol(Something, Decl(valueUsedAsTypeArgument.ts, 3, 5)) - -// Type argument, should show new error -type SomeFoo = Foo; ->SomeFoo : Symbol(SomeFoo, Decl(valueUsedAsTypeArgument.ts, 3, 21)) ->Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) - -// Type alias -type SomeBar = Something; ->SomeBar : Symbol(SomeBar, Decl(valueUsedAsTypeArgument.ts, 6, 30)) - -// Nested type arguments, should show new error -type SomeOther = Other>; ->SomeOther : Symbol(SomeOther, Decl(valueUsedAsTypeArgument.ts, 9, 25)) ->Other : Symbol(Other, Decl(valueUsedAsTypeArgument.ts, 0, 27)) ->Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) - -// Misuse of value -const x: Something = []; ->x : Symbol(x, Decl(valueUsedAsTypeArgument.ts, 15, 5)) - -// Numeric literal type -type LiteralNumberFoo = Foo<1>; ->LiteralNumberFoo : Symbol(LiteralNumberFoo, Decl(valueUsedAsTypeArgument.ts, 15, 24)) ->Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) - -// String literal type -type LiteralStringFoo = Foo<'test'>; ->LiteralStringFoo : Symbol(LiteralStringFoo, Decl(valueUsedAsTypeArgument.ts, 18, 31)) ->Foo : Symbol(Foo, Decl(valueUsedAsTypeArgument.ts, 0, 0)) - diff --git a/tests/baselines/reference/valueUsedAsTypeArgument.types b/tests/baselines/reference/valueUsedAsTypeArgument.types deleted file mode 100644 index 6363c0e7f64f2..0000000000000 --- a/tests/baselines/reference/valueUsedAsTypeArgument.types +++ /dev/null @@ -1,37 +0,0 @@ -=== tests/cases/compiler/valueUsedAsTypeArgument.ts === -type Foo = { items: T }; ->Foo : Foo ->items : T - -type Other = {}; ->Other : Other - -const Something = []; ->Something : any[] ->[] : undefined[] - -// Type argument, should show new error -type SomeFoo = Foo; ->SomeFoo : Foo - -// Type alias -type SomeBar = Something; ->SomeBar : any - -// Nested type arguments, should show new error -type SomeOther = Other>; ->SomeOther : Other> - -// Misuse of value -const x: Something = []; ->x : any ->[] : undefined[] - -// Numeric literal type -type LiteralNumberFoo = Foo<1>; ->LiteralNumberFoo : Foo<1> - -// String literal type -type LiteralStringFoo = Foo<'test'>; ->LiteralStringFoo : Foo<"test"> - diff --git a/tests/cases/compiler/valueUsedAsTypeArgument.ts b/tests/cases/compiler/valueUsedAsTypeArgument.ts deleted file mode 100644 index 4f0a39d353b9d..0000000000000 --- a/tests/cases/compiler/valueUsedAsTypeArgument.ts +++ /dev/null @@ -1,22 +0,0 @@ -type Foo = { items: T }; -type Other = {}; - -const Something = []; - -// Type argument, should show new error -type SomeFoo = Foo; - -// Type alias -type SomeBar = Something; - -// Nested type arguments, should show new error -type SomeOther = Other>; - -// Misuse of value -const x: Something = []; - -// Numeric literal type -type LiteralNumberFoo = Foo<1>; - -// String literal type -type LiteralStringFoo = Foo<'test'>; \ No newline at end of file