如果我具有以下接口定义:
interface ModalProps {
onClose: (event: {}, reason: 'backdropClick' | 'escapeKeyDown'): void;
}
现在,我要添加其他原因:
interface CustomModalProps {
onClose: (event: {}, reason: 'backdropClick' | 'escapeKeyDown' | 'cancelClick'): void;
}
有什么方法可以从CustomModalProps内引用ModalProps onClose原因,这样我就不必复制值了?
interface CustomModalProps extends ModalProps {
onClose: (event: {}, reason: ??? &| 'cancelClick'): void
}
答案 0 :(得分:2)
我们的类型。
type ModalReason = 'backdropClick' | 'escapeKeyDown';
type CustomModaReason = ModalReason | 'cancelClick';
interface ModalProps {
onClose: (event: {}, reason: ModalReason): void;
}
interface CustomModalProps {
onClose: (event: {}, reason: CustomModaReason): void;
}