打字稿中的私有界面

bsr*_*bsr 1 javascript typescript

在typescript中,总是需要导出接口.我在以下情况下得到错误:

错误TS2019:导出的类'Test'实现私有接口'ITest'.

module xxx { 
    interface ITest {
    }

    export class Test implements ITest {
    }
}
Run Code Online (Sandbox Code Playgroud)

bas*_*rat 5

在你的情况下是的.如果要导出实现它的类,则需要:

module xxx { 
    export interface ITest {
        name: string
    }

    export class Test implements ITest {
       name = "ddsd"     
        constructor() {
         ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

或者你可以在外面移动ITest:

interface ITest {
    name: string
}

module xxx { 

    export class Test implements ITest {
       name = "ddsd"     
        constructor() {
         ...
        }
    }
}
Run Code Online (Sandbox Code Playgroud)