【发布时间】:2016-05-20 20:28:59
【问题描述】:
我正在使用typings 来加载类型定义。我的项目使用 bluebird 作为 promise 实现。这两行在我的typings.json:
"Promise": "github:DefinitelyTyped/DefinitelyTyped/bluebird/bluebird.d.ts#dd328830dddffbe19e9addd7cf8532cbd3600816",
"node": "github:DefinitelyTyped/DefinitelyTyped/node/node.d.ts#48c1e3c1d6baefa4f1a126f188c27c4fefd36bff",
typings(1.0.3 版)生成以下typings/index.d.ts:
/// <reference path="globals/node/index.d.ts" />
/// <reference path="globals/Promise/index.d.ts" />
编译时,tsc 在我使用 Promise 的所有地方都会抱怨,例如与:
error TS2339: Property 'exists' does not exist on type 'Promise<IResourcePatched> | Promise<string>'
但是,代码是正确的并且以前可以工作。现在我发现,如果我将typings/index.d.ts 中两行的顺序切换为先引用bluebird,我的程序就可以像以前一样编译和工作......
显然 tsc 只接受它首先看到的 Promise 的定义,并且来自 node 的 Promise 定义似乎与来自 bluebird 的定义略有不同。
问题是:如何实现,typings 按我需要的顺序列出index.d.ts 中的依赖关系,或者如何从节点的定义中排除 Promise 声明?
PS:有足够声誉的人可以在 StackOverflow 上为打字添加标签吗?
更新:我只是尝试更改 typings.json 中的分型顺序,但 index.d.ts 中的节点分型总是出现在 Promise 之前。它们似乎是按字母顺序排列的……
更新 2:它似乎不是 node 中的 Promise 定义,而是模块“es6-shim”中的一个定义,这是 angular2 所必需的依赖项。所以其他名字,同样的问题:顺序。
注意:TypeScript-Compiler 配置为生成 es5 代码。
【问题讨论】:
标签: typescript