jc28
jc28

Reputation: 1882

How to omit one property from interface, but not with type in TypeScript?

I need to make one interface that extends from 2 another, but I get the error: Interface 'IModalProps' cannot simultaneously extend types 'ModalProps' and 'ModalRNProps'.   Named property 'onShow' of types 'ModalProps' and 'ModalRNProps' are not identical.:

export interface IModalProps extends ModalProps, ModalRNProps {
  showCloseButton?: boolean;
  showDoneBar?: boolean;
}

I can do omit only with type like this:

type OmitA = Omit<ModalProps, "onShow">; 

But I can not after make extends with type, because it is possible only with interfaces. Can you tell me please how can I omit one property from the interface and after create one extendable interface from a few interfaces?

Upvotes: 1

Views: 992

Answers (1)

satanTime
satanTime

Reputation: 13539

try interfaces instead of types

export interface IModalProps {
  showCloseButton?: boolean;
  showDoneBar?: boolean;
}


export interface Test extends Omit<IModalProps, 'showDoneBar'> {

}

const test: Test = {
    showCloseButton: true,
    showDoneBar: false, // fails
 };

Playground

Upvotes: 3

Related Questions