This repository was archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
This repository was archived by the owner on Aug 17, 2023. It is now read-only.
type error after compile #4
Copy link
Copy link
Closed
Description
- I'm submitting a ...
[x] bug report
[ ] feature request
[ ] question about the decisions made in the repository
[ ] question about how to use this project
- Summary
this is _getEventHandlers
method in MaskedInput.tsx
:
// MaskedInput.tsx
// ...
_keyPressPropName() {
if (typeof navigator !== 'undefined') {
return navigator.userAgent.match(/Android/i)
? 'onBeforeInput'
: 'onKeyPress';
}
return 'onKeyPress';
}
_getEventHandlers() {
return {
onChange: this._onChange,
onKeyDown: this._onKeyDown,
onPaste: this._onPaste,
[this._keyPressPropName()]: this._onKeyPress
};
}
// ...
...And the source is compiled as:
// compiled type signature file
// ...
_keyPressPropName(): "onBeforeInput" | "onKeyPress";
_getEventHandlers(): {
[x: string]: (e: React.ChangeEvent<HTMLInputElement>) => void;
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
onKeyDown: (e: any) => void;
onPaste: (e: React.ClipboardEvent<any>) => void;
};
Though _keyPressPropName
is Union type, because of typescript issue that union type cannot be a key of object, _getEventHandlers
is compiled with x
key which is a string type.
This makes compile error Property 'onPaste' of type '(e: ClipboardEvent<any>) => void' is not assignable to string index type '(e: ChangeEvent<HTMLInputElement>)
. this should be fixed by more explicit type declaration on method:
_getEventHandlers(): {
onChange: (TChangeEvent) => void;
onKeyDown: (TChangeEvent) => void;
onPaste: (TClipboardEvent) => void;
onBeforeInput?: (TChangeEvent) => void;
onKeyPress?: (TChangeEvent) => void;
} {
return {
onChange: this._onChange,
onKeyDown: this._onKeyDown,
onPaste: this._onPaste,
[this._keyPressPropName()]: this._onKeyPress
};
}
which is compiled liked this:
_getEventHandlers(): {
onChange: (TChangeEvent: any) => void;
onKeyDown: (TChangeEvent: any) => void;
onPaste: (TClipboardEvent: any) => void;
onBeforeInput?: (TChangeEvent: any) => void;
onKeyPress?: (TChangeEvent: any) => void;
};
- Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. StackOverflow, personal fork, etc.)
Metadata
Metadata
Assignees
Labels
No labels