Skip to content

Fix: override html prop types by custom prop types #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

richard-ejem
Copy link

@richard-ejem richard-ejem commented Feb 21, 2020

Motivation

Intersected with HTMLDivElement, e.g. onBlur's argument resolved to FocusEvent<HTMLTextAreaElement> | FocusEvent<HTMLDivElement>. Now it resolves properly to FocusEvent<HTMLTextAreaElement> only.

Test plan

(unrelated mandatory props omitted for simplicity)

Before:

// TS7006: Parameter 'e' implicitly has an 'any' type.
<Editor onBlur={(e) => console.log('Blurred!');} />

// TS2322: Type '(e: FocusEvent<HTMLTextAreaElement>) => void' is not assignable to type '((event: FocusEvent<HTMLDivElement>) => void) & ((e: FocusEvent<HTMLTextAreaElement>) => void)'
<Editor onBlur={(e: FocusEvent<HTMLTextAreaElement>) => console.log('Blurred!');} />

// compiles, but is inexact e will never be FocusEvent<HTMLDivElement>
<Editor onBlur={(e: FocusEvent<HTMLTextAreaElement> | FocusEvent<HTMLDivElement>) => console.log('Blurred!');} />

After:

// OK
<Editor onBlur={(e: FocusEvent<HTMLTextAreaElement>) => console.log('Blurred!');} />

// inference works now too
<Editor onBlur={(e) => console.log('Blurred!');} />

Intersected with HTMLDivElement, e.g. onBlur's argument resolved to
FocusEvent<HTMLTextAreaElement> | FocusEvent<HTMLDivElement>.
Now it resolves properly to FocusEvent<HTMLTextAreaElement> only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant