How to exclude a key from an interface in TypeScript

后端 未结 4 506
既然无缘
既然无缘 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:45

    There is utility-types library that has Subtract mapped type:

    import { Subtract } from 'utility-types';
    
    type Props = { name: string; age: number; visible: boolean };
    type DefaultProps = { age: number };
    
    type RequiredProps = Subtract;
    // Expect: { name: string; visible: boolean; }
    

提交回复
热议问题