美文网首页我爱编程
TypeScript 学习笔记 之插件安装

TypeScript 学习笔记 之插件安装

作者: 大树值殇 | 来源:发表于2017-05-25 08:24 被阅读0次

    关于类型定义文件的管理工具,经历了 tsd、typings 两代进化,现在官方推荐的方式是使用 npm 进行管理

    1.安装之前,先用bower安装相应插件 例如安装CKEditor :

    bower install --help

    bower install --save ckeditor#full/4.5.11

    bower home ckeditor

    bower search ckeditor

    bower install ckeditor

    bower install angular-ui-router --save

    2.升级TypeScript确认版本号在 2.0 以上

    $ npm uninstall -g typescript$ npm install -g typescript$ tsc -v

    npm install --save-dev typescript

    3.类型定义库

    Github 上的开源项目DefinitelyTyped用于维护常见 JavaScript 库的类型定义。

    通过TypeSearch搜索对应库的类型定义文件。

    4.安装类型定义文件

    以 angularjs 为例,在工程根目录下执行如下命令以安装类型定义文件

    $ npm install @types/angular --save-dev

    对应的类型定义文件将被安装在工程根目录/node_modules/@types目录下。

    5.配置tsconfig.json

    工程根目录/src下的tsconfig.json用于配置 TypeScript 编译选项。在使用 npm 进行类型定义文件管理时,它的配置如下

    {

    "compilerOptions": {

    "module": "commonjs",

    "target": "ES5",

    "noImplicitAny": true,

    "removeComments": true,

    "preserveConstEnums": true,

    "sourceMap": true,

    "rootDir": "./",

    "outDir": "../www"

    },

    "exclude": [

    "bower_components",

    "components",

    "../www"

    ],

    "include": [

    "../node_modules/@types",

    "./"

    ]

    }

    在未配置typeroots的前提下,TypeScript 编译器会自动寻找引入node_modules/@types目录中的类型定义文件。更多信息请参考tsconfig-json types typeroots and types

    5.如果你用的 Netbeans  要升级TypeScript Editor 插件

    匹配 TypeScript 2,Netbeans 插件也需升级。在nbts下载最新的 .nbm 插件并导入 Netbeans 即可。

    以下是typings时代的安转方法,可以参考:

    2、然后再安装:typescript 相应支持插件

    插件地址(包含绝大部分插件):https://github.com/DefinitelyTyped/DefinitelyTyped

    安装时要注意的事项:

    先全局安装:npm install typings --global

    让后cd 到项目typings 目录下,进行以下命令的操作

    安装命令说明: typings install -h

    相关文章

      网友评论

        本文标题:TypeScript 学习笔记 之插件安装

        本文链接:https://www.haomeiwen.com/subject/mryaxxtx.html