簡介
一些js庫擴展了JavaScript的特性和語法,但是TypeScript編譯器並不識別,
通過typings.json配置可以輔助IDE,給出有智能的提示信息,以及重構的依據。
因此需要在typings.json文件中配置TypeScript類型定義文件(文件名后綴為.d.ts)
自己的理解
typings就方便TypeScript識別、編譯、智能提示TypeScript無法識別的JS庫的特性和語法
命令集
#全局安裝typings
npm install typings --global
#搜索
typings search module
#查找
typings search --name module
#安裝(默認使用npm)
typings install module --save
#使用數據源為dt安裝
typings install dt~module --global --save
#其他數據源安裝
typings install env~module --global --save
typings install npm~module --save
#可以直接用github,后面為github的項目路徑https://github.com/DefinitelyTyped/DefinitelyTyped #后面為提交的版本號,可以不寫
typings install github:DefinitelyTyped/DefinitelyTyped/jasmine/jasmine.d.ts#38fb591c6eba840e0b53d1110302b8e4fb04652c --global --save
#顯示所有引用
cat typings/index.d.ts
數據源
npm - dependencies from NPM
github - dependencies directly from GitHub (E.g. Duo, JSPM)
bower - dependencies from Bower
common - "standard" libraries without a known "source"
shared - shared library functionality
lib - shared environment functionality (mirror of shared) (--global)
env - environments (E.g. atom, electron) (--global)
global - global (window.<var>) libraries (--global)
dt - typings from DefinitelyTyped (usually --global)