摘要:rule as any as Foo // 双重断言
阅读全文
摘要:index.ts function foo(bar: string, baz: number): (string | number)[] { return [bar, baz]; } bash tsc index.ts
阅读全文
摘要:bash npm i ts-node -g npm i nodemon -g index.ts const foo: string = 'Hello' console.log(foo) bash nodemon index.ts
阅读全文
摘要:index.ts interface Cat { name: string run(): void } interface Fish { name: string swim(): void } function isCat(animal: Cat | Fish): boolean { return
阅读全文
摘要:index.ts const foo: string[] = ["foo", "bar"]
阅读全文
摘要:index.ts const lilei: [string, number] = ["Lilei", 23]
阅读全文
摘要:index.ts abstract class Foo { constructor() {} className = "Foo"; } class FooChild extends Foo { constructor() { super(); } } // const foo = new Foo()
阅读全文
摘要:index.ts let decLiteral: number = 6 // 10 let hexLiteral: number = 0xf00d // 16 let binaryLiteral: number = 0b1010 // 2 let octalLiteral: number = 0o7
阅读全文
摘要:index.ts function foo(name: string, age?: number) { console.log(name + age); } foo("a"); // "aundefined"
阅读全文
摘要:index.ts interface IPerson { name: string age: number gender?: number } const lilei: IPerson = { name: "Lilei", age: 23, }
阅读全文
摘要:index.ts interface IPerson { name: string age: number family?: any[] // Error,因为不是任意类型的子集 [propName: string]: string | number // 一般设置 any,因为其他类型必需是任意类
阅读全文
摘要:index.ts function foo(...rest: any[]) { console.log(rest) } foo(1, 2, 3) // [1, 2, 3]
阅读全文
摘要:tsconfig.json { "compilerOptions": { "target": "ESNEXT", "lib": ["DOM", "ESNEXT"], }, } index.ts const a = 11n
阅读全文
摘要:browser https://www.typescriptlang.org/dt/search?search=
阅读全文
摘要:index.ts const lilei: [string, number] = ["Lilei", 23]; lilei.push(NaN); // 3 lilei.push("NaN"); // NaN lilei.push(true); // string | number -> Error
阅读全文
摘要:index.ts class Foo { constructor(public name: string, public readonly age: number) {} } const foo = new Foo("foo", 23); console.log(foo.name); console
阅读全文
摘要:tsconfig.json { "compilerOptions": { "target": "ESNEXT", "lib": ["DOM", "ESNEXT"], "module": "commonjs", "sourceMap": true, "outDir": "./dist", "modul
阅读全文
摘要:1. 使用: npm -v 查看是否安装了 npm , 如果没有安装, 请前往 Nodejs 官网 下载安装, 下图表示已经安装 npm , 版本为: 6.9.0 . 2. 使用 tsc -v 查看是否安装了 typescript , 下面表示已经安装, 版本为: 3.5.3, 如果没有安装, 可以
阅读全文