简体   繁体   中英

private interface in typescript

In typescript, does interface always needs to be exported. I get error in the below case:

error TS2019: Exported class 'Test' implements private interface 'ITest'.

module xxx { 
    interface ITest {
    }

    export class Test implements ITest {
    }
}

In your case yes. You need to if you want to export the class that implements it:

module xxx { 
    export interface ITest {
        name: string
    }

    export class Test implements ITest {
       name = "ddsd"     
        constructor() {
         ...
        }
    }
}

Alternatively you can move ITest outside:

interface ITest {
    name: string
}

module xxx { 

    export class Test implements ITest {
       name = "ddsd"     
        constructor() {
         ...
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM