Module 无法解析在同一模块中但在不同文件中定义的接口
暗中 字段/base.tsModule 无法解析在同一模块中但在不同文件中定义的接口,module,namespaces,typescript,typescript1.7,Module,Namespaces,Typescript,Typescript1.7,暗中 字段/base.ts /// <reference path="../_all.ts" /> module SomeApp.fields { export interface IField {} export class Field implements IFields {} } // 模块SomeApp.fields{ 导出接口IField{} 导出类字段实现IFields{} } 在fields/CharField.ts中 /// <reference
/// <reference path="../_all.ts" />
module SomeApp.fields {
export interface IField {}
export class Field implements IFields {}
}
//
模块SomeApp.fields{
导出接口IField{}
导出类字段实现IFields{}
}
在fields/CharField.ts中
/// <reference path="../_all.ts" />
module SomeApp.fields {
import IField = SomeApp.fields.IField;
export interface ICharField extends IField {}
export class Field implements IFields {}
}
//
模块SomeApp.fields{
导入IField=SomeApp.fields.IField;
导出接口ICharField扩展IField{}
导出类字段实现IFields{}
}
在_all.ts中:
/// <reference path="fields/base.ts" />
/// <reference path="fields/CharField.ts" />
//
///
但这不起作用,我从CharField.ts
文件中得到了这个错误:
错误:(7,39)TS2305:模块“SomeApp.fields”没有导出的成员
“Ifeld”
那么我的代码有什么问题吗?您的问题提出了几个问题:
.
+-- tsconfig.json
+-- references.d.ts
+-- src
| +-- myInterface.ts
| +-- myClass.ts
tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"out": "result.js",
"sourceMap": true
},
"files": [
"src/myClass.ts"
]
}
参考文献d.ts:
/// <reference path="src/myInterface.ts" />
/// <reference path="src/myClass.ts" />
myClass.ts:
/// <reference path="../references.d.ts" />
module MyNameSpace {
export class MyClass implements IMyInterface {
// ...
}
}
//
模块MyNameSpace{
导出类MyClass实现IMyInterface{
// ...
}
}
上面的例子是有效的,您的例子不起作用的确切原因可能是上面提到的1、2或3点中的任何一点
/// <reference path="../references.d.ts" />
module MyNameSpace {
export class MyClass implements IMyInterface {
// ...
}
}