跳到主要内容

React synthetic event type

导出了 React 的合成事件类型声明

import type { Fiber } from 'react-reconciler/src/ReactInternalTypes';
import type { DOMEventName } from './_DOMEventNames';

// 调度配置
export type DispatchConfig = {
dependencies?: Array<DOMEventName>;
phasedRegistrationNames: {
bubbled: null | string;
captured: null | string;
};
registrationName?: string;
};
// 基础合成事件
type BaseSyntheticEvent = {
isPersistent: () => boolean;
isPropagationStopped: () => boolean;
_dispatchInstances?: null | Array<Fiber | null> | Fiber;
_dispatchListeners?: null | Array<Function> | Function;
_targetInst: Fiber;
nativeEvent: Event;
target?: mixed;
relatedTarget?: mixed;
type: string;
currentTarget: null | EventTarget;
};
// 已知 React 合成事件
export type KnownReactSyntheticEvent = BaseSyntheticEvent & {
_reactName: string;
};
// 未知的 React 合成事件
export type UnknownReactSyntheticEvent = BaseSyntheticEvent & {
_reactName: null;
};

// React合成事件
export type ReactSyntheticEvent =
| KnownReactSyntheticEvent
| UnknownReactSyntheticEvent;