TypeScript/tests/baselines/reference/typeAssertions.errors.txt
Josh Goldberg 541e553163
Specific diagnostic suggestions for unexpected keyword or identifier (#43005)
Error message improvement for unexpected tokens in the following situations:

* A word was parsed that seems to have a low edit distance from a known common keyword
* A word was parsed that seems to be a known common keyword and a name _without_ a space in-between
* Parsing in a particular type of node (mostly a class property declaration) got a different word or token than expected

___

* Specific diagnostic suggestions for unexpected keywords or identifier

* Don't reach into there, that's not allowed

* Improved error when there is already an initializer

* Specific module error message for invalid template literal strings

* Skip 'unexpected keyword or identifier' diagnostics for declare nodes

* Improve error for function calls in type positions

* Switch class properties to old diagnostic

* Corrected errors in class members and reused existing textToKeywordObj map

* Corrected more baselines from the merge

* Update src/compiler/parser.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>

* Mostly addressed feedback

* Clarified function call type message

* Split up and clarified parsing vs error functions

* Swap interface name complaints back, and skip new errors on unknown (invalid) tokens

* Used tokenToString, not a raw semicolon

* Inline getExpressionText helper

* Remove remarks in src/compiler/parser.ts

Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
2021-07-14 13:50:55 -07:00

121 lines
8 KiB
Plaintext

tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,9): error TS2558: Expected 0 type arguments, but got 1.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2352: Conversion of type 'SomeOther' to type 'SomeBase' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2352: Conversion of type 'SomeOther' to type 'SomeDerived' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Type 'SomeOther' is missing the following properties from type 'SomeDerived': x, p
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2352: Conversion of type 'SomeDerived' 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 '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. 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.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,17): error TS2693: 'string' only refers to a type, but is being used as a value here.
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. 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 TS1434: Unexpected keyword or identifier.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,44): error TS2693: 'string' only refers to a type, but is being used as a value here.
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): error TS1128: Declaration or statement expected.
==== tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts (18 errors) ====
// Function call whose argument is a 1 arg generic function call with explicit type arguments
function fn1<T>(t: T) { }
function fn2(t: any) { }
fn1(fn2<string>(4)); // Error
~~~~~~
!!! error TS2558: Expected 0 type arguments, but got 1.
var a: any;
var s: string;
// Type assertion of non - unary expression
var a = <any>"" + 4;
var s = "" + <any>4;
class SomeBase {
private p;
}
class SomeDerived extends SomeBase {
private x;
}
class SomeOther {
private q;
}
// Type assertion should check for assignability in either direction
var someBase = new SomeBase();
var someDerived = new SomeDerived();
var someOther = new SomeOther();
someBase = <SomeBase>someDerived;
someBase = <SomeBase>someBase;
someBase = <SomeBase>someOther; // Error
~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Conversion of type 'SomeOther' to type 'SomeBase' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Property 'p' is missing in type 'SomeOther' but required in type 'SomeBase'.
!!! related TS2728 tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts:15:13: 'p' is declared here.
someDerived = <SomeDerived>someDerived;
someDerived = <SomeDerived>someBase;
someDerived = <SomeDerived>someOther; // Error
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Conversion of type 'SomeOther' to type 'SomeDerived' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
!!! error TS2352: Type 'SomeOther' is missing the following properties from type 'SomeDerived': x, p
someOther = <SomeOther>someDerived; // Error
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Conversion of type 'SomeDerived' 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.
!!! error TS2352: Property 'q' is missing in type 'SomeDerived' but required in type 'SomeOther'.
!!! related TS2728 tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts:21:13: 'q' is declared here.
someOther = <SomeOther>someBase; // Error
~~~~~~~~~~~~~~~~~~~
!!! 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.
!!! error TS2352: Property 'q' is missing in type 'SomeBase' but required in type 'SomeOther'.
!!! related TS2728 tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts:21:13: 'q' is declared here.
someOther = <SomeOther>someOther;
// Type assertion cannot be a type-predicate type
var numOrStr: number | string;
var str: string;
if(<numOrStr is string>(numOrStr === undefined)) { // Error
~~~~~~~~
!!! error TS2749: 'numOrStr' refers to a value, but is being used as a type here. Did you mean 'typeof numOrStr'?
~~
!!! error TS1005: '>' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~~~~~~
!!! error TS1005: ')' expected.
~~~~~~
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
~
!!! error TS1005: ';' expected.
str = numOrStr; // Error, no narrowing occurred
~~~
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
}
if((numOrStr === undefined) as numOrStr is string) { // Error
~~~~~~~~
!!! error TS2749: 'numOrStr' refers to a value, but is being used as a type here. Did you mean 'typeof numOrStr'?
~~
!!! error TS1005: ')' expected.
~~
!!! error TS2304: Cannot find name 'is'.
~~~~~~
!!! error TS1434: Unexpected keyword or identifier.
~~~~~~
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
~
!!! error TS1128: Declaration or statement expected.
}