How to exclude a key from an interface in TypeScript

后端 未结 4 507
既然无缘
既然无缘 2021-02-05 04:38

In TypeScript, you can combine two interface types like this

interface Foo {
    var1: string
}

interface Bar {
    var2: string
}

type Combined = Foo & Ba         


        
4条回答
  •  温柔的废话
    2021-02-05 04:46

    In TypeScript 2.8 you can now do the following:

    interface Foo {
        attribute1: string;
        optional2?: string;
        excludePlease: string;
    }
    
    // Typescript 3.5+ defines Omit for you.
    // In earlier Typescript versions define Omit:
    // type Omit = Pick>
    
    // Use Omit to exclude one or more fields (use "excludePlease"|"field2"|"field3" etc to exclude multiple)
    type Bar = Omit
    const b: Bar = {
        attribute1: ''
    };
    

    So in relation to your question the following might be what you want:

    export default function valueHOC

    ( Comp: React.ComponentClass

    | React.StatelessComponent

    ): React.ComponentClass> { return class WrappedComponent extends React.Component, State> { render () { return ( ) } }

提交回复
热议问题