简体   繁体   中英

Extending a union type from an extended interface

If I have this interface definition:

interface ModalProps {
    onClose: (event: {}, reason: 'backdropClick' | 'escapeKeyDown'): void;
}

Now I want to add an additional reason:

interface CustomModalProps {
    onClose: (event: {}, reason: 'backdropClick' | 'escapeKeyDown' | 'cancelClick'): void;
}

Is there any way I can reference the ModalProps onClose reason from within CustomModalProps, so that I don't have to copy the values?

interface CustomModalProps extends ModalProps {
  onClose: (event: {}, reason: ??? &| 'cancelClick'): void
}

Us types.

type ModalReason = 'backdropClick' | 'escapeKeyDown';

type CustomModaReason = ModalReason | 'cancelClick';

interface ModalProps {
    onClose: (event: {}, reason: ModalReason): void;
}

interface CustomModalProps {
    onClose: (event: {}, reason: CustomModaReason): void;
}

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