【问题标题】:private interface in typescript打字稿中的私有接口
【发布时间】:2014-03-06 03:26:13
【问题描述】:
在打字稿中,界面是否总是需要导出。在以下情况下出现错误:
错误 TS2019:导出的类“Test”实现私有接口“ITest”。
module xxx {
interface ITest {
}
export class Test implements ITest {
}
}
【问题讨论】:
标签:
javascript
typescript
【解决方案1】:
在你的情况下是的。如果要导出实现它的类,则需要:
module xxx {
export interface ITest {
name: string
}
export class Test implements ITest {
name = "ddsd"
constructor() {
...
}
}
}
您也可以将 ITest 移到外面:
interface ITest {
name: string
}
module xxx {
export class Test implements ITest {
name = "ddsd"
constructor() {
...
}
}
}