2016-02-05 263 views
0

我有以下文件結構:打字稿沒有找到定義

+ 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代碼(版本0.10.6)立即突出顯示this line,並顯示錯誤「Can not find namespace sequelize'」。

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

即使sequelize.d.ts成功引用在與文件的頂部:/// <reference path="../../typings/sequelize/sequelize.d.ts" />

回答

0

以上「降低」示例工作如果zzrm模塊不帶引號聲明:

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

當我更新sequelize.d.ts時,我沒有注意到模塊聲明已從

declare module sequelize { ... } 

declare module "sequelize" { ... } 

這在打字稿文檔"Ambient External Modules"下提及,但我還沒有完全還沒有想出如何將這些零部件全部結合在一起,爲什麼他們需要你還可以添加import * as zzrm from 'z_module';