on 3dcf025 help sign in
110 lines 1.7 kB history raw
1let letNumber = 10;
2const constNumber = 20;
4const bool: boolean = true;
5const list: number[] = [1, 2, 3];
6const array: Array<number> = [1, 2, 3];
7const pair: [string, number] = ['hello', 10];
9for (let i = 0; i < list.length; i += 1) {
10 console.log(list[i]);
13if (bool) {
14 console.log('True');
15} else {
16 console.log('False');
19const str: string = 'Jake';
20const templateStr: string = `Hello, ${str}!`;
22// A comment
24/*
25 * Multiline comments
26 * Multiline comments
27 */
29interface SquareConfig {
30 label: string;
31 color?: string;
32 width?: number;
33 [propName: string]: any;
36interface SearchFunc {
37 (source: string, subString: string): boolean;
40enum Color {
41 Red,
42 Green,
45type Easing = "ease-in" | "ease-out" | "ease-in-out";
47class Greeter {
48 private readonly greeting: string;
50 constructor(message: string) {
51 this.greeting = message;
52 }
54 greet() {
55 return "Hello, " + this.greeting;
56 }
59let greeter = new Greeter("world");
61class Animal {
62 move(distanceInMeters: number = 0) {
63 console.log(`Animal moved ${distanceInMeters}m.`);
64 }
67class Dog extends Animal {
68 bark() {
69 console.log("Woof! Woof!");
70 }
73const dog = new Dog();
74dog.bark();
75dog.move(10);
76dog.bark();
78class Point {
79 x: number;
80 y: number;
83interface Point3d extends Point {
84 z: number;
87let point3d: Point3d = { x: 1, y: 2, z: 3 };
89function add(x, y) {
90 return x + y;
93let myAdd = function (x, y) {
94 return x + y;
95};
97(function () {
98 console.log('IIFE');
99}());
101function identity<T>(arg: T): T {
102 return arg;
105let myIdentity: <T>(arg: T) => T = identity;
107class GenericNumber<T> {
108 zeroValue: T;
109 add: (x: T, y: T) => T;