Created
June 24, 2021 06:12
-
-
Save julenwang/1b2ef18ce0c60c8f4901f02382d770e2 to your computer and use it in GitHub Desktop.
react-modal-promise.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'react-modal-promise'; | |
import { InstanceOptions } from 'react-modal-promise/lib/types'; | |
import { ComponentType } from 'react'; | |
declare module 'react-modal-promise' { | |
type ModalResolveValue<Value> = | |
| { | |
type: 'COMPLETE'; | |
value?: Value; | |
} | |
| { | |
type: 'CANCEL'; | |
value?: Value; | |
}; | |
interface ModalProps<Resolve extends ModalResolveValue, Reject = unknown> { | |
isOpen: boolean; | |
// 通过 type 处理打开或者关闭的状态 | |
onResolve: (value: Resolve) => void; | |
// 仅用于处理 error | |
onReject: (value: Reject) => void; | |
} | |
type InferPropsValue<T> = T extends ModalProps<infer V> ? V : never; | |
const create: { | |
<T extends ModalProps>(Component: ComponentType<T>, options?: InstanceOptions): Omit< | |
T, | |
keyof ModalProps<unknown> | |
> extends Record<string, never> | |
? (props?: Omit<T, keyof ModalProps<unknown>>) => Promise<InferPropsValue<T>> | |
: (props: Omit<T, keyof ModalProps<unknown>>) => Promise<InferPropsValue<T>>; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment