【问题标题】:Migrating Ionic 2 to Typescript 2.0 RC将 Ionic 2 迁移到 Typescript 2.0 RC
【发布时间】:2017-01-09 10:24:12
【问题描述】:

目前我正在使用 Ionic 2.0.0-beta.37。它使用打字稿 1.8.x 。我正在尝试使用 typescript 为我们提供 D3 版本 4,但来自 d3-v4-definitelytyped 的类型使用 Typescript 2.x。我在输入时遇到编译错误,在d3-v4-definitelytyped repo 上提出问题后,我了解到我需要在 Ionic 2 项目中使用 TS 2.x。

这是我得到的错误:

TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(150,30): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(167,24): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(173,55): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-axis/index.d.ts(191,24): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-brush/index.d.ts(30,37): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-chord/index.d.ts(38,56): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-chord/index.d.ts(39,25): Error TS1110: Type expected.
TypeScript error: /Users/arash1/Projects/brite-front-end/node_modules/@types/d3-chord/index.d.ts(41,59): Error TS1110: Type expected.

我查看了我的主 IONIC 目录中的 package.json 文件,我没有看到 typescript 作为依赖项,所以我认为它正在使用其他东西来定义版本。我明白了:

  • “ionic-gulp-browserify-typescript”:“2.0.0”
  • "tslint-ionic-rules": "^0.0.3"
  • “tsify”:“0.16.0”

于是我进入tslint-ionic-rules 看到:

"devDependencies": {
    "typescript": "^1.8.10"
  }

只是为了尝试我运行npm install typescript@rctslint-ionic-rules node_modules 中安装新版本,看看我是否得到同样的错误。错误仍然存​​在。

有人可以就如何做到这一点提供指导吗? RC 最近在MFST Blog 上公布了。

【问题讨论】:

    标签: angular ionic2 typescript2.0


    【解决方案1】:

    在开始之前,我还没有完全解决问题,但我至少可以解释一下我尝试过的方法。 确切地说,我没有在我的 gulp.file 中使用 lint,但我确实注意到 ionic2 使用了 browserify,当您查看 ionic-gulp-browserify-typescript 模块时,您可以看到:

    tsifyOptions:{}

    您可以使用它来设置您想要使用的 TS 版本。

    例子:

    1. 在本地安装 typescript 2.x
    2. 在您的构建任务中添加 tsifyOptions: {}

    它应该看起来像这样:

    gulp.task('build', ['clean'], function(done){
      runSequence(
        ['sass', 'html', 'fonts', 'scripts'],
        function(){
          buildBrowserify({
            minify: isRelease,
            browserifyOptions: {
              debug: !isRelease
            },
            uglifyOptions: {
              mangle: false
            },
            tsifyOptions: {
              typescript: require('your typescript')
            }
          }).on('end', done);
        }
      );
    });
    

    【讨论】:

    • 简单明了,你可以从你的 gulp 中禁用所有的 tslint。毕竟 tslint 只是标准的集合
    猜你喜欢
    • 1970-01-01
    • 2016-11-04
    • 1970-01-01
    • 2016-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多