typescript-tutorial
typescript-tutorial copied to clipboard
TypeScript 入门教程
https://ts.xcatliu.com/introduction/get-typescript.html
添加函数返回值的类型定义
按照自己的理解写了很简单的示例和使用场景,和官网的不同,请参考一下。
 const enum 编译后的值可以是字符串,如果使用常数枚举的话,会误导读者以为编译后都是数字
在声明文件这一章中: https://ts.xcatliu.com/basics/declaration-files#shen-me-shi-sheng-ming-wen-jian 您提到只要把声明文件放在本地src目录下,不用引用就可以直接使用。但是试了下不行呢。我有两个文件,在同一个src目录下: ```javascript // index.d.ts declare let gl: string; ``` ```javascript // index.ts console.log(gl); // 直接报错:找不到gl的定义 ``` `tsconfig.json`中有`include`的配置: ``` "include": ["src/**/*"] ``` 看起来typescript没有解析`index.d.ts`。 这是啥问题呢? 补充:在`index.ts`中使用`///`就不报错了: `/// `
重载报错
函数的类型/重载.ts(4,39): error TS2366: Function lacks ending return statement and return type does not include 'undefined'. ``` function reverse(x: number): number; function reverse(x: string): string; function reverse(x: number | string): number...
章节地址 https://ts.xcatliu.com/advanced/tuple#jian-dan-de-li-zi 当赋值或访问一个已知索引的元素时,会得到正确的类型: let tom: [string, number]; tom[0] = 'Tom'; tom[1] = 25; tom[0].slice(1); tom[1].toFixed(2); 也可以只赋值其中一项: let tom: [string, number]; tom[0] = 'Tom'; 示例代码报错,查询ts官网和其他网站,并没有发现这种写法,只能整个数组一起赋值 let tom: [string, number]; tom =...