简体   繁体   中英

Extend an interface using an existing interface

I have this interface in typescript:

interface VolRenderingProps extends JSX.mesh {
    // Additional props
    url: string
    interpolation?: number
    alphaCorrection?: number
    steps?: number
}

I need to separate the additional props from the declaration itself (because I need to use the type AdditionalProps in other place). So Im trying to do something like:

interface AdditionalProps {
    url: string
    interpolation?: number
    alphaCorrection?: number
    steps?: number
}
interface VolRenderingProps extends JSX.mesh {
   ...AdditionalProps // I suppose this is totally wrong but you get the idea :)
}

You can define VolRenderingProps to extend multiple interfaces - so JSX.mesh and AdditionalProps . Please check the following code:

interface AdditionalProps {
    url: string
    interpolation?: number
    alphaCorrection?: number
    steps?: number
}
interface VolRenderingProps extends JSX.mesh, AdditionalProps {
   // and so on
}

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