TypeScript/tests/baselines/reference/genericTypeAssertions2.errors.txt
Matt McCutchen da64479a64 Improve the error message when asserting to a type that is not
comparable to the original.

Also improve the error message for implicit conversion of a symbol to a
string in a template literal, which previously shared the error message
with type assertions.

Fixes #25539.  Addresses #25870.
2018-07-25 19:13:10 -04:00

37 lines
2.2 KiB
Plaintext

tests/cases/compiler/genericTypeAssertions2.ts(10,5): error TS2322: Type 'B<string>' is not assignable to type 'A<number>'.
Types of property 'foo' are incompatible.
Type '(x: string) => void' is not assignable to type '(x: number) => void'.
Types of parameters 'x' and 'x' are incompatible.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/genericTypeAssertions2.ts(11,5): error TS2322: Type 'A<number>' is not assignable to type 'B<number>'.
Property 'bar' is missing in type 'A<number>'.
tests/cases/compiler/genericTypeAssertions2.ts(13,21): error TS2352: Conversion of type 'undefined[]' to type 'A<number>' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
Property 'foo' is missing in type 'undefined[]'.
==== tests/cases/compiler/genericTypeAssertions2.ts (3 errors) ====
class A<T> { foo(x: T) { } }
class B<T> extends A<T> {
bar(): T {
return null;
}
}
var foo = new A<number>();
var r: A<string> = <B<string>>new B();
var r2: A<number> = <B<string>>new B(); // error
~~
!!! error TS2322: Type 'B<string>' is not assignable to type 'A<number>'.
!!! error TS2322: Types of property 'foo' are incompatible.
!!! error TS2322: Type '(x: string) => void' is not assignable to type '(x: number) => void'.
!!! error TS2322: Types of parameters 'x' and 'x' are incompatible.
!!! error TS2322: Type 'number' is not assignable to type 'string'.
var r3: B<number> = <A<number>>new B(); // error
~~
!!! error TS2322: Type 'A<number>' is not assignable to type 'B<number>'.
!!! error TS2322: Property 'bar' is missing in type 'A<number>'.
var r4: A<number> = <A<number>>new A();
var r5: A<number> = <A<number>>[]; // error
~~~~~~~~~~~~~
!!! error TS2352: Conversion of type 'undefined[]' to type 'A<number>' 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 'foo' is missing in type 'undefined[]'.