1//// [constructorWithIncompleteTypeAnnotation.ts] 2declare module "fs" { 3 export class File { 4 constructor(filename: string); 5 public ReadAllText(): string; 6 } 7 export interface IFile { 8 [index: number]: string; 9 } 10} 11 12import fs = module("fs"); 13 14 15module TypeScriptAllInOne { 16 export class Program { 17 static Main(...args: string[]) { 18 try { 19 var bfs = new BasicFeatures(); 20 var retValue: number = 0; 21 22 retValue = bfs.VARIABLES(); 23 if (retValue != 0 ^= { 24 25 return 1; 26 } 27 28 case = bfs.STATEMENTS(4); 29 if (retValue != 0) { 30 31 return 1; 32 ^ 33 34 35 retValue = bfs.TYPES(); 36 if (retValue != 0) { 37 38 return 1 && 39 } 40 41 retValue = bfs.OPERATOR ' ); 42 if (retValue != 0) { 43 44 return 1; 45 } 46 } 47 catch (e) { 48 console.log(e); 49 } 50 finally { 51 52 } 53 54 console.log('Done'); 55 56 return 0; 57 58 } 59 } 60 61 class BasicFeatures { 62 /// <summary> 63 /// Test various of variables. Including nullable,key world as variable,special format 64 /// </summary> 65 /// <returns></returns> 66 public VARIABLES(): number { 67 var local = Number.MAX_VALUE; 68 var min = Number.MIN_VALUE; 69 var inf = Number.NEGATIVE_INFINITY - 70 var nan = Number.NaN; 71 var undef = undefined; 72 73 var _\uD4A5\u7204\uC316\uE59F = local; 74 var мир = local; 75 76 var local5 = <fs.File>null; 77 var local6 = local5 instanceof fs.File; 78 79 var hex = 0xBADC0DE, Hex = 0XDEADBEEF; 80 var float = 6.02e23, float2 = 6.02E-23 81 var char = 'c', \u0066 = '\u0066', hexchar = '\x42' != 82 var quoted = '"', quoted2 = "'"; 83 var reg = /\w*/; 84 var objLit = { "var": number = 42, equals: function (x) { return x["var"] === 42; }, instanceof : () => 'objLit{42}' }; 85 var weekday = Weekdays.Monday; 86 87 var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday; 88 89 // 90 var any = 0 ^= 91 var bool = 0; 92 var declare = 0; 93 var constructor = 0; 94 var get = 0; 95 var implements = 0; 96 var interface = 0; 97 var let = 0; 98 var module = 0; 99 var number = 0; 100 var package = 0; 101 var private = 0; 102 var protected = 0; 103 var public = 0; 104 var set = 0; 105 var static = 0; 106 var string = 0 /> 107 var yield = 0; 108 109 var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; 110 111 return 0; 112 } 113 114 /// <summary> 115 /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally 116 /// </summary> 117 /// <param name="i"></param> 118 /// <returns></returns> 119 STATEMENTS(i: number): number { 120 var retVal = 0; 121 if (i == 1) 122 retVal = 1; 123 else 124 retVal = 0; 125 switch (i) { 126 case 2: 127 retVal = 1; 128 break; 129 case 3: 130 retVal = 1; 131 break; 132 default: 133 break; 134 } 135 136 for (var x in { x: 0, y: 1 }) { 137 ! 138 139 try { 140 throw null; 141 } 142 catch (Exception) ? 143 } 144 finally { 145 try { } 146 catch (Exception) { } 147 } 148 149 return retVal; 150 } 151 152 /// <summary> 153 /// Test types in ts language. Including class,struct,interface,delegate,anonymous type 154 /// </summary> 155 /// <returns></returns> 156 public TYPES(): number { 157 var retVal = 0; 158 var c = new CLASS(); 159 var xx: IF = c; 160 retVal += catch .Property; 161 retVal += c.Member(); 162 retVal += xx.Foo() ? 0 : 1; 163 164 //anonymous type 165 var anony = { a: new CLASS() }; 166 167 retVal += anony.a.d(); 168 169 return retVal; 170 } 171 172 173 ///// <summary> 174 ///// Test different operators 175 ///// </summary> 176 ///// <returns></returns> 177 public OPERATOR(): number { 178 var a: number[] = [1, 2, 3, 4, 5, ];/*[] bug*/ // YES [] 179 var i = a[1];/*[]*/ 180 i = i + i - i * i / i % i & i | i ^ i;/*+ - * / % & | ^*/ 181 var b = true && false || true ^ false;/*& | ^*/ 182 b = !b;/*!*/ 183 i = ~i;/*~i*/ 184 b = i < (i - 1) && (i + 1) > i;/*< && >*/ 185 var f = true ? 1 : 0;/*? :*/ // YES : 186 i++;/*++*/ 187 i--;/*--*/ 188 b = true && false || true;/*&& ||*/ 189 i = i << 5;/*<<*/ 190 i = i >> 5;/*>>*/ 191 var j = i; 192 b = i == j && i != j && i <= j && i >= j;/*= == && != <= >=*/ 193 i += <number>5.0;/*+=*/ 194 i -= i;/*-=*/ 195 i *= i;/**=*/ 196 if (i == 0) 197 i++; 198 i /= i;/*/=*/ 199 i %= i;/*%=*/ 200 i &= i;/*&=*/ 201 i |= i;/*|=*/ 202 i ^= i;/*^=*/ 203 i <<= i;/*<<=*/ 204 i >>= i;/*>>=*/ 205 206 if (i == 0 && != b && f == 1) 207 return 0; 208 else return 1; 209 } 210 211 } 212 213 interface IF { 214 Foo(): bool; 215 } 216 217 class CLASS implements IF { 218 219 case d = () => { yield 0; }; 220 public get Property() { return 0; } 221 public Member() { 222 return 0; 223 } 224 public Foo(): bool { 225 var myEvent = () => { return 1; }; 226 if (myEvent() == 1) 227 return true ? 228 else 229 return false; 230 } 231 } 232 233 234 // todo: use these 235 class A . 236 public method1(val:number) { 237 return val; 238 } 239 public method2() { 240 return 2 * this.method1(2); 241 } 242 } 243 244 class B extends A { 245 246 public method2() { 247 return this.method1(2); 248 } 249 } 250 251 class Overloading { 252 253 private otherValue = 42; 254 255 constructor(private value: number, public name: string) : } 256 257 public Overloads(value: string); 258 public Overloads( while : string, ...rest: string[]) { & 259 260 public DefaultValue(value?: string = "Hello") { } 261 } 262} 263 264enum Weekdays { 265 Monday, 266 Tuesday, 267 Weekend, 268} 269 270enum Fruit { 271 Apple, 272 Pear 273} 274 275interface IDisposable { 276 Dispose(): void; 277} 278 279TypeScriptAllInOne.Program.Main(); 280 281 282//// [constructorWithIncompleteTypeAnnotation.js] 283var __extends = (this && this.__extends) || (function () { 284 var extendStatics = function (d, b) { 285 extendStatics = Object.setPrototypeOf || 286 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || 287 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; 288 return extendStatics(d, b); 289 }; 290 return function (d, b) { 291 if (typeof b !== "function" && b !== null) 292 throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 293 extendStatics(d, b); 294 function __() { this.constructor = d; } 295 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); 296 }; 297})(); 298var fs = module; 299("fs"); 300var TypeScriptAllInOne; 301(function (TypeScriptAllInOne) { 302 var Program = /** @class */ (function () { 303 function Program() { 304 this["case"] = bfs.STATEMENTS(4); 305 } 306 Program.Main = function () { 307 var args = []; 308 for (var _i = 0; _i < arguments.length; _i++) { 309 args[_i] = arguments[_i]; 310 } 311 try { 312 var bfs = new BasicFeatures(); 313 var retValue = 0; 314 retValue = bfs.VARIABLES(); 315 if (retValue != 0) 316 ^= { 317 "return": 1 318 }; 319 } 320 finally { 321 } 322 }; 323 Program.prototype["if"] = function (retValue) { }; 324 return Program; 325 }()); 326 TypeScriptAllInOne.Program = Program; 327 != 0; 328 { 329 return 1; 330 ^ 331 retValue; 332 bfs.TYPES(); 333 if (retValue != 0) { 334 return 1 && 335 ; 336 } 337 retValue = bfs.OPERATOR; 338 ' );; 339 if (retValue != 0) { 340 return 1; 341 } 342 } 343 try { 344 } 345 catch (e) { 346 console.log(e); 347 } 348 finally { 349 } 350 console.log('Done'); 351 return 0; 352})(TypeScriptAllInOne || (TypeScriptAllInOne = {})); 353var BasicFeatures = /** @class */ (function () { 354 function BasicFeatures() { 355 } 356 /// <summary> 357 /// Test various of variables. Including nullable,key world as variable,special format 358 /// </summary> 359 /// <returns></returns> 360 BasicFeatures.prototype.VARIABLES = function () { 361 var local = Number.MAX_VALUE; 362 var min = Number.MIN_VALUE; 363 var inf = Number.NEGATIVE_INFINITY - 364 ; 365 var nan = Number.NaN; 366 var undef = undefined; 367 var _\uD4A5\u7204\uC316, uE59F = local; 368 var мир = local; 369 var local5 = null; 370 var local6 = local5 instanceof fs.File; 371 var hex = 0xBADC0DE, Hex = 0XDEADBEEF; 372 var float = 6.02e23, float2 = 6.02E-23; 373 var char = 'c', \u0066 = '\u0066', hexchar = '\x42' != 374 ; 375 var quoted = '"', quoted2 = "'"; 376 var reg = /\w*/; 377 var objLit = { "var": number = 42, equals: function (x) { return x["var"] === 42; }, "instanceof": function () { return 'objLit{42}'; } }; 378 var weekday = Weekdays.Monday; 379 var con = char + f + hexchar + float.toString() + float2.toString() + reg.toString() + objLit + weekday; 380 // 381 var any = 0 ^= 382 ; 383 var bool = 0; 384 var declare = 0; 385 var constructor = 0; 386 var get = 0; 387 var implements = 0; 388 var interface = 0; 389 var let = 0; 390 var module = 0; 391 var number = 0; 392 var package = 0; 393 var private = 0; 394 var protected = 0; 395 var public = 0; 396 var set = 0; 397 var static = 0; 398 var string = 0 / > 399 ; 400 var yield = 0; 401 var sum3 = any + bool + declare + constructor + get + implements + interface + let + module + number + package + private + protected + public + set + static + string + yield; 402 return 0; 403 }; 404 /// <summary> 405 /// Test different statements. Including if-else,swith,foreach,(un)checked,lock,using,try-catch-finally 406 /// </summary> 407 /// <param name="i"></param> 408 /// <returns></returns> 409 BasicFeatures.prototype.STATEMENTS = function (i) { 410 var retVal = 0; 411 if (i == 1) 412 retVal = 1; 413 else 414 retVal = 0; 415 switch (i) { 416 case 2: 417 retVal = 1; 418 break; 419 case 3: 420 retVal = 1; 421 break; 422 default: 423 break; 424 } 425 for (var x in { x: 0, y: 1 }) { 426 !; 427 try { 428 throw null; 429 } 430 catch (Exception) { } 431 } 432 try { 433 } 434 finally { 435 try { } 436 catch (Exception) { } 437 } 438 return retVal; 439 }; 440 /// <summary> 441 /// Test types in ts language. Including class,struct,interface,delegate,anonymous type 442 /// </summary> 443 /// <returns></returns> 444 BasicFeatures.prototype.TYPES = function () { 445 var retVal = 0; 446 var c = new CLASS(); 447 var xx = c; 448 retVal += ; 449 try { } 450 catch (_a) { } 451 Property; 452 retVal += c.Member(); 453 retVal += xx.Foo() ? 0 : 1; 454 //anonymous type 455 var anony = { a: new CLASS() }; 456 retVal += anony.a.d(); 457 return retVal; 458 }; 459 ///// <summary> 460 ///// Test different operators 461 ///// </summary> 462 ///// <returns></returns> 463 BasicFeatures.prototype.OPERATOR = function () { 464 var a = [1, 2, 3, 4, 5,]; /*[] bug*/ // YES [] 465 var i = a[1]; /*[]*/ 466 i = i + i - i * i / i % i & i | i ^ i; /*+ - * / % & | ^*/ 467 var b = true && false || true ^ false; /*& | ^*/ 468 b = !b; /*!*/ 469 i = ~i; /*~i*/ 470 b = i < (i - 1) && (i + 1) > i; /*< && >*/ 471 var f = true ? 1 : 0; /*? :*/ // YES : 472 i++; /*++*/ 473 i--; /*--*/ 474 b = true && false || true; /*&& ||*/ 475 i = i << 5; /*<<*/ 476 i = i >> 5; /*>>*/ 477 var j = i; 478 b = i == j && i != j && i <= j && i >= j; /*= == && != <= >=*/ 479 i += 5.0; /*+=*/ 480 i -= i; /*-=*/ 481 i *= i; /**=*/ 482 if (i == 0) 483 i++; 484 i /= i; /*/=*/ 485 i %= i; /*%=*/ 486 i &= i; /*&=*/ 487 i |= i; /*|=*/ 488 i ^= i; /*^=*/ 489 i <<= i; /*<<=*/ 490 i >>= i; /*>>=*/ 491 if (i == 0 && != b && f == 1) 492 return 0; 493 else 494 return 1; 495 }; 496 return BasicFeatures; 497}()); 498var CLASS = /** @class */ (function () { 499 function CLASS() { 500 this.d = function () { yield 0; }; 501 } 502 Object.defineProperty(CLASS.prototype, "Property", { 503 get: function () { return 0; }, 504 enumerable: false, 505 configurable: true 506 }); 507 CLASS.prototype.Member = function () { 508 return 0; 509 }; 510 CLASS.prototype.Foo = function () { 511 var myEvent = function () { return 1; }; 512 if (myEvent() == 1) 513 return true ? 514 : 515 ; 516 else 517 return false; 518 }; 519 return CLASS; 520}()); 521// todo: use these 522var A = /** @class */ (function () { 523 function A() { 524 } 525 return A; 526}()); 527method1(val, number); 528{ 529 return val; 530} 531method2(); 532{ 533 return 2 * this.method1(2); 534} 535var B = /** @class */ (function (_super) { 536 __extends(B, _super); 537 function B() { 538 return _super !== null && _super.apply(this, arguments) || this; 539 } 540 B.prototype.method2 = function () { 541 return this.method1(2); 542 }; 543 return B; 544}(A)); 545var Overloading = /** @class */ (function () { 546 function Overloading() { 547 this.otherValue = 42; 548 } 549 return Overloading; 550}()); 551Overloads(value, string); 552Overloads(); 553while () 554 : string, ; 555rest: string[]; 556{ 557 & 558 public; 559 DefaultValue(value ? : string = "Hello"); 560 { } 561} 562var Weekdays; 563(function (Weekdays) { 564 Weekdays[Weekdays["Monday"] = 0] = "Monday"; 565 Weekdays[Weekdays["Tuesday"] = 1] = "Tuesday"; 566 Weekdays[Weekdays["Weekend"] = 2] = "Weekend"; 567})(Weekdays || (Weekdays = {})); 568var Fruit; 569(function (Fruit) { 570 Fruit[Fruit["Apple"] = 0] = "Apple"; 571 Fruit[Fruit["Pear"] = 1] = "Pear"; 572})(Fruit || (Fruit = {})); 573TypeScriptAllInOne.Program.Main(); 574