Back

typescript - 在vuejs中的使用和解读 tsconfig.json, *.d.ts

发布时间: 2022-01-06 07:28:00

*.d.ts 的作用:

这里的d 是declaration的缩写, 本文件为 声明文件,告诉.js 文件中返回的类型是啥。

例如,一个ts文件命名为:  some_file.ts , 那么,转换成 js后,会有3个文件:

some_file.d.ts
some_file.js
some_file.js.map

其中:

some_file.ts   包含了函数的实现

some_file.d.ts 只包含了该函数的返回值

some_file.js 则是编译后的 函数的实现

tsconfig.json 的作用:引入第三方文件

例如:

内容看起来如下:

{   
   "compilerOptions": {
     "target": "esnext",                                              
     "module": "esnext",                                              
     "strict": true,
..........
   "include": [
     "src/**/*.ts",
     "src/**/*.tsx",
     "src/**/*.vue",
     "typings/**/*.ts"
   ],
   "exclude": [
     "node_modules"
   ]
 }

这样的话,可以在ts文件中直接使用  src/ 和 typings 目录下定义的class啥的

(window as any) 是类型检查和转换。 等同于<any>window , 用于避免ts的类型转换错误

例如:  (window as any).ethereum

https://stackoverflow.com/questions/42551681/what-does-this-as-any-mean-in-this-typescript-snippet

Back