I just check the type definition and found this,
type of e is FormEvent<HTMLInputElement>,
Then the FormEvent is defined as,
interface FormEvent<T = Element> extends SyntheticEvent<T> {
}
The FormEvent is extended the SyntheticEvent, which defined as,
interface SyntheticEvent<T = Element, E = Event> extends BaseSyntheticEvent<E, EventTarget & T, EventTarget> {}
And when I check the definition of BaseSyntheticEvent, I found this,
interface BaseSyntheticEvent<E = object, C = any, T = any> {
nativeEvent: E;
currentTarget: C;
target: T;
bubbles: boolean;
cancelable: boolean;
defaultPrevented: boolean;
eventPhase: number;
isTrusted: boolean;
preventDefault(): void;
isDefaultPrevented(): boolean;
stopPropagation(): void;
isPropagationStopped(): boolean;
persist(): void;
timeStamp: number;
type: string;
}
Here we don't have a property call data. Then I just saw that there is a type call, CompositionEvent which extends SyntheticEvent.
interface CompositionEvent<T = Element> extends SyntheticEvent<T, NativeCompositionEvent> {
data: string;
}
And it has the field data;
So I did,
<input type="text" onBeforeInput={(e:SyntheticEvent) => {
let event = e as CompositionEvent;
console.log(event.data);
}} />
Or,
interface CustomEvent extends SyntheticEvent {
data ?: string
}
<input type="text" onBeforeInput={(event:CustomEvent) => {
console.log(event.data);
}} />