typescript 学习笔记
typescript 学习笔记
申明全局类型,不用import导入,可以直接使用
-
项目更目录下创建
typings目录 -
在
typings中添加index.d.ts, 在其中定义需要的类型interface MyType { foo: string, bar: string[] } -
修改
tsconfig.json,添加字段typeRoots{ "compilerOptions": { "typeRoots": ["./node_modules/@types/", "./typings"], } }
在ts项目中 import 一个本地图片, 会报错cannot find module '.png'
在项目的.d.ts文件中,增加类型申明
declare module '*.svg'
declare module '*.png'
declare module '*.jpg'
declare module '*.jpeg'
declare module '*.gif'
declare module '*.bmp'
declare module '*.tiff'