1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
|
=== tests/cases/conformance/statements/throwStatements/throwStatements.ts ===
// all legal
interface I {
id: number;
>id : number
}
class C implements I {
>C : C
id: number;
>id : number
}
class D<T>{
>D : D<T>
source: T;
>source : T
recurse: D<T>;
>recurse : D<T>
wrapped: D<D<T>>
>wrapped : D<D<T>>
}
function F(x: string): number { return 42; }
>F : (x: string) => number
>x : string
>42 : 42
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 : 9.9
throw aNumber;
>aNumber : number
var aString = 'this is a string';
>aString : string
>'this is a string' : "this is a string"
throw aString;
>aString : string
var aDate = new Date(12);
>aDate : Date
>new Date(12) : Date
>Date : DateConstructor
>12 : 12
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 : 12
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
>'' : ""
var aLambda = (x) => 2;
>aLambda : (x: any) => number
>(x) => 2 : (x: any) => number
>x : any
>2 : 2
throw aLambda;
>aLambda : (x: any) => number
throw aLambda(1);
>aLambda(1) : number
>aLambda : (x: any) => number
>1 : 1
var aModule = M;
>aModule : typeof M
>M : typeof M
throw aModule;
>aModule : typeof M
throw typeof M;
>typeof M : "string" | "number" | "bigint" | "boolean" | "symbol" | "undefined" | "object" | "function"
>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 : 0
throw false;
>false : false
throw null;
>null : null
throw undefined;
>undefined : undefined
throw 'a string';
>'a string' : "a string"
throw function () { return 'a string' };
>function () { return 'a string' } : () => string
>'a string' : "a string"
throw <T>(x:T) => 42;
><T>(x:T) => 42 : <T>(x: T) => number
>x : T
>42 : 42
throw { x: 12, y: 13 };
>{ x: 12, y: 13 } : { x: number; y: number; }
>x : number
>12 : 12
>y : number
>13 : 13
throw [];
>[] : undefined[]
throw ['a', ['b']];
>['a', ['b']] : (string | string[])[]
>'a' : "a"
>['b'] : string[]
>'b' : "b"
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
|