118 lines
5.9 KiB
Plaintext
118 lines
5.9 KiB
Plaintext
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(5,5): error TS2346: Supplied parameters do not match any signature of call target.
|
|
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(31,12): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeBase'.
|
|
Property 'p' is missing in type 'SomeOther'.
|
|
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(35,15): error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'.
|
|
Property 'x' is missing in type 'SomeOther'.
|
|
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(37,13): error TS2352: Type 'SomeDerived' cannot be converted to type 'SomeOther'.
|
|
Property 'q' is missing in type 'SomeDerived'.
|
|
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(38,13): error TS2352: Type 'SomeBase' cannot be converted to type 'SomeOther'.
|
|
Property 'q' is missing in type 'SomeBase'.
|
|
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(44,5): error TS2304: Cannot find name '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 TS2304: Cannot find name 'string'.
|
|
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 TS2304: Cannot find name '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.
|
|
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,44): error TS2304: Cannot find name 'string'.
|
|
tests/cases/conformance/expressions/typeAssertions/typeAssertions.ts(48,50): error TS1005: ';' 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 TS2346: Supplied parameters do not match any signature of call target.
|
|
|
|
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: Type 'SomeOther' cannot be converted to type 'SomeBase'.
|
|
!!! error TS2352: Property 'p' is missing in type 'SomeOther'.
|
|
|
|
someDerived = <SomeDerived>someDerived;
|
|
someDerived = <SomeDerived>someBase;
|
|
someDerived = <SomeDerived>someOther; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2352: Type 'SomeOther' cannot be converted to type 'SomeDerived'.
|
|
!!! error TS2352: Property 'x' is missing in type 'SomeOther'.
|
|
|
|
someOther = <SomeOther>someDerived; // Error
|
|
~~~~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2352: Type 'SomeDerived' cannot be converted to type 'SomeOther'.
|
|
!!! error TS2352: Property 'q' is missing in type 'SomeDerived'.
|
|
someOther = <SomeOther>someBase; // Error
|
|
~~~~~~~~~~~~~~~~~~~
|
|
!!! error TS2352: Type 'SomeBase' cannot be converted to type 'SomeOther'.
|
|
!!! error TS2352: Property 'q' is missing in type 'SomeBase'.
|
|
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 TS2304: Cannot find name 'numOrStr'.
|
|
~~
|
|
!!! error TS1005: '>' expected.
|
|
~~
|
|
!!! error TS2304: Cannot find name 'is'.
|
|
~~~~~~
|
|
!!! error TS1005: ')' expected.
|
|
~~~~~~
|
|
!!! error TS2304: Cannot find name 'string'.
|
|
~
|
|
!!! 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 TS2304: Cannot find name 'numOrStr'.
|
|
~~
|
|
!!! error TS1005: ')' expected.
|
|
~~
|
|
!!! error TS2304: Cannot find name 'is'.
|
|
~~~~~~
|
|
!!! error TS1005: ';' expected.
|
|
~~~~~~
|
|
!!! error TS2304: Cannot find name 'string'.
|
|
~
|
|
!!! error TS1005: ';' expected.
|
|
}
|
|
|
|
|