266 lines
4.2 KiB
Text
266 lines
4.2 KiB
Text
=== tests/cases/conformance/statements/throwStatements/throwStatements.ts ===
|
|
// all legal
|
|
|
|
interface I {
|
|
>I : I
|
|
|
|
id: number;
|
|
>id : number
|
|
}
|
|
|
|
class C implements I {
|
|
>C : C
|
|
>I : I
|
|
|
|
id: number;
|
|
>id : number
|
|
}
|
|
|
|
class D<T>{
|
|
>D : D<T>
|
|
>T : T
|
|
|
|
source: T;
|
|
>source : T
|
|
>T : T
|
|
|
|
recurse: D<T>;
|
|
>recurse : D<T>
|
|
>D : D<T>
|
|
>T : T
|
|
|
|
wrapped: D<D<T>>
|
|
>wrapped : D<D<T>>
|
|
>D : D<T>
|
|
>D : D<T>
|
|
>T : T
|
|
}
|
|
|
|
function F(x: string): number { return 42; }
|
|
>F : (x: string) => number
|
|
>x : string
|
|
>42 : number
|
|
|
|
module M {
|
|
>M : typeof M
|
|
|
|
export class A {
|
|
>A : A
|
|
|
|
name: string;
|
|
>name : string
|
|
}
|
|
|
|
export function F2(x: number): string { return x.toString(); }
|
|
>F2 : (x: number) => string
|
|
>x : number
|
|
>x.toString() : string
|
|
>x.toString : (radix?: number) => string
|
|
>x : number
|
|
>toString : (radix?: number) => string
|
|
}
|
|
|
|
var aNumber = 9.9;
|
|
>aNumber : number
|
|
>9.9 : number
|
|
|
|
throw aNumber;
|
|
>aNumber : number
|
|
|
|
var aString = 'this is a string';
|
|
>aString : string
|
|
>'this is a string' : string
|
|
|
|
throw aString;
|
|
>aString : string
|
|
|
|
var aDate = new Date(12);
|
|
>aDate : Date
|
|
>new Date(12) : Date
|
|
>Date : DateConstructor
|
|
>12 : number
|
|
|
|
throw aDate;
|
|
>aDate : Date
|
|
|
|
var anObject = new Object();
|
|
>anObject : Object
|
|
>new Object() : Object
|
|
>Object : ObjectConstructor
|
|
|
|
throw anObject;
|
|
>anObject : Object
|
|
|
|
var anAny = null;
|
|
>anAny : any
|
|
>null : null
|
|
|
|
throw anAny;
|
|
>anAny : any
|
|
|
|
var anOtherAny = <any> new C();
|
|
>anOtherAny : any
|
|
><any> new C() : any
|
|
>new C() : C
|
|
>C : typeof C
|
|
|
|
throw anOtherAny;
|
|
>anOtherAny : any
|
|
|
|
var anUndefined = undefined;
|
|
>anUndefined : any
|
|
>undefined : undefined
|
|
|
|
throw anUndefined;
|
|
>anUndefined : any
|
|
|
|
var aClass = new C();
|
|
>aClass : C
|
|
>new C() : C
|
|
>C : typeof C
|
|
|
|
throw aClass;
|
|
>aClass : C
|
|
|
|
var aGenericClass = new D<string>();
|
|
>aGenericClass : D<string>
|
|
>new D<string>() : D<string>
|
|
>D : typeof D
|
|
|
|
throw aGenericClass;
|
|
>aGenericClass : D<string>
|
|
|
|
var anObjectLiteral = { id: 12 };
|
|
>anObjectLiteral : { id: number; }
|
|
>{ id: 12 } : { id: number; }
|
|
>id : number
|
|
>12 : number
|
|
|
|
throw anObjectLiteral;
|
|
>anObjectLiteral : { id: number; }
|
|
|
|
var aFunction = F;
|
|
>aFunction : (x: string) => number
|
|
>F : (x: string) => number
|
|
|
|
throw aFunction;
|
|
>aFunction : (x: string) => number
|
|
|
|
throw aFunction('');
|
|
>aFunction('') : number
|
|
>aFunction : (x: string) => number
|
|
>'' : string
|
|
|
|
var aLambda = (x) => 2;
|
|
>aLambda : (x: any) => number
|
|
>(x) => 2 : (x: any) => number
|
|
>x : any
|
|
>2 : number
|
|
|
|
throw aLambda;
|
|
>aLambda : (x: any) => number
|
|
|
|
throw aLambda(1);
|
|
>aLambda(1) : number
|
|
>aLambda : (x: any) => number
|
|
>1 : number
|
|
|
|
var aModule = M;
|
|
>aModule : typeof M
|
|
>M : typeof M
|
|
|
|
throw aModule;
|
|
>aModule : typeof M
|
|
|
|
throw typeof M;
|
|
>typeof M : string
|
|
>M : typeof M
|
|
|
|
var aClassInModule = new M.A();
|
|
>aClassInModule : M.A
|
|
>new M.A() : M.A
|
|
>M.A : typeof M.A
|
|
>M : typeof M
|
|
>A : typeof M.A
|
|
|
|
throw aClassInModule;
|
|
>aClassInModule : M.A
|
|
|
|
var aFunctionInModule = M.F2;
|
|
>aFunctionInModule : (x: number) => string
|
|
>M.F2 : (x: number) => string
|
|
>M : typeof M
|
|
>F2 : (x: number) => string
|
|
|
|
throw aFunctionInModule;
|
|
>aFunctionInModule : (x: number) => string
|
|
|
|
// no initializer or annotation, so this is an 'any'
|
|
var x;
|
|
>x : any
|
|
|
|
throw x;
|
|
>x : any
|
|
|
|
// literals
|
|
throw 0.0;
|
|
>0.0 : number
|
|
|
|
throw false;
|
|
>false : boolean
|
|
|
|
throw null;
|
|
>null : null
|
|
|
|
throw undefined;
|
|
>undefined : undefined
|
|
|
|
throw 'a string';
|
|
>'a string' : string
|
|
|
|
throw function () { return 'a string' };
|
|
>function () { return 'a string' } : () => string
|
|
>'a string' : string
|
|
|
|
throw <T>(x:T) => 42;
|
|
><T>(x:T) => 42 : <T>(x: T) => number
|
|
>T : T
|
|
>x : T
|
|
>T : T
|
|
>42 : number
|
|
|
|
throw { x: 12, y: 13 };
|
|
>{ x: 12, y: 13 } : { x: number; y: number; }
|
|
>x : number
|
|
>12 : number
|
|
>y : number
|
|
>13 : number
|
|
|
|
throw [];
|
|
>[] : undefined[]
|
|
|
|
throw ['a', ['b']];
|
|
>['a', ['b']] : (string | string[])[]
|
|
>'a' : string
|
|
>['b'] : string[]
|
|
>'b' : string
|
|
|
|
throw /[a-z]/;
|
|
>/[a-z]/ : RegExp
|
|
|
|
throw new Date();
|
|
>new Date() : Date
|
|
>Date : DateConstructor
|
|
|
|
throw new C();
|
|
>new C() : C
|
|
>C : typeof C
|
|
|
|
throw new Object();
|
|
>new Object() : Object
|
|
>Object : ObjectConstructor
|
|
|
|
throw new D<number>();
|
|
>new D<number>() : D<number>
|
|
>D : typeof D
|
|
|