Conformance tests for 'as' operator
This commit is contained in:
parent
fa198a5cef
commit
2b44dcac4d
|
@ -0,0 +1,8 @@
|
||||||
|
var as = 43;
|
||||||
|
var x = undefined as number;
|
||||||
|
var y = (null as string).length;
|
||||||
|
var z = Date as any as string;
|
||||||
|
|
||||||
|
// Should parse as a union type, not a bitwise 'or' of (32 as number) and 'string'
|
||||||
|
var j = 32 as number|string;
|
||||||
|
j = '';
|
|
@ -0,0 +1 @@
|
||||||
|
var x = 23 as string;
|
|
@ -0,0 +1,10 @@
|
||||||
|
declare function tag(...x: any[]): any;
|
||||||
|
|
||||||
|
var a = `${123 + 456 as number}`;
|
||||||
|
var b = `leading ${123 + 456 as number}`;
|
||||||
|
var c = `${123 + 456 as number} trailing`;
|
||||||
|
var d = `Hello ${123} World` as string;
|
||||||
|
var e = `Hello` as string;
|
||||||
|
var f = 1 + `${1} end of string` as string;
|
||||||
|
var g = tag `Hello ${123} World` as string;
|
||||||
|
var h = tag `Hello` as string;
|
|
@ -0,0 +1,10 @@
|
||||||
|
class Foo { }
|
||||||
|
declare function as(...args: any[]);
|
||||||
|
|
||||||
|
// Example 1
|
||||||
|
var x = 10
|
||||||
|
as `Hello world`; // should not error
|
||||||
|
|
||||||
|
// Example 2
|
||||||
|
var y = 20
|
||||||
|
as(Foo); // should emit
|
|
@ -0,0 +1,8 @@
|
||||||
|
interface A<T> { x: T; }
|
||||||
|
interface B { m: string; }
|
||||||
|
|
||||||
|
// Make sure this is a type assertion to an array type, and not nested comparison operators.
|
||||||
|
var x: any;
|
||||||
|
var y = x as A<B>[];
|
||||||
|
var z = y[0].m; // z should be string
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
// should error
|
||||||
|
var x = (v => v) as (x: number) => string;
|
|
@ -0,0 +1,4 @@
|
||||||
|
var a = 20;
|
||||||
|
var b = a as string;
|
||||||
|
var as = "hello";
|
||||||
|
var as1 = as as string;
|
Loading…
Reference in a new issue