Conformance tests for 'as' operator

This commit is contained in:
Ryan Cavanaugh 2015-06-18 14:03:14 -07:00
parent fa198a5cef
commit 2b44dcac4d
7 changed files with 43 additions and 0 deletions

View file

@ -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 = '';

View file

@ -0,0 +1 @@
var x = 23 as string;

View file

@ -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;

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,2 @@
// should error
var x = (v => v) as (x: number) => string;

View file

@ -0,0 +1,4 @@
var a = 20;
var b = a as string;
var as = "hello";
var as1 = as as string;