【问题标题】: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() {
         ...
        }
    }
}

【讨论】:

    猜你喜欢
    • 2020-01-06
    • 2017-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 2016-04-04
    • 1970-01-01
    • 2020-08-14
    相关资源
    最近更新 更多