[英]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?有什么方法可以从 CustomModalProps 中引用 ModalProps onClose 原因,这样我就不必复制这些值了?
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.