TypeScript没有找到定义

时间:2016-02-05 15:51:16

标签: typescript definition ambient

我有以下文件结构:

+ src
|  test.ts
|  z_module.d.ts
tsconfig.json

test.ts

// does nothing?
/// <reference path="./z_module.d.ts" />
// can't now write:
var a: zzrm.zzrmObject;

// have to use:    
import * as zzrm from 'zzrm';
var a: zzrm.zzrmObject;

z_module.d.ts

declare module "zzrm" {
  export interface zzrmObject {id: string}
}

我试图减少问题,但可能会错误地减少它。问题最初来自试图使用sequelize-auto-ts。 Downloading the repo升级sequelize.d.ts 并在Visual Studio Code(版本0.10.6)中打开,会立即突出显示this line,错误为“找不到命名空间'sequelize'。 “

var Sequelize:sequelize.SequelizeStatic = require('sequelize');
              ^^^^^^^^^

尽管sequelize.d.ts已在文件顶部成功引用:/// <reference path="../../typings/sequelize/sequelize.d.ts" />

1 个答案:

答案 0 :(得分:0)

如果声明zzrm模块没有引号,则上面的“简化”示例有效:

declare module zzrm {
  export interface zzrmObject {id: string}
}

当我更新sequelize.d.ts时,我没有注意到模块声明已从

更改
declare module sequelize { ... }

declare module "sequelize" { ... }

"Ambient External Modules"下的TypeScript文档中提到了这一点,但我还没有弄清楚这些部分如何组合在一起以及为什么它们还要求您添加import * as zzrm from 'z_module';