-
Notifications
You must be signed in to change notification settings - Fork 6
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
Update bau.d.ts to have automatic types for event listeners as props #108
Conversation
Thanks for the PR, unfortunately, it creates a regression: cd bau/examples/bau-ts-test
npm run build src/main.ts:469:11 - error TS2345: Argument of type '{ placeholder: string; value: State<string>; oninput: ({ target }: { target: HTMLInputElement;}) => string; }' is not assignable to parameter of type 'PropsAll<HTMLInputElement> | undefined'.
Types of property 'oninput' are incompatible.
Type '({ target }: { target: HTMLInputElement;}) => string' is not assignable to type '(this: GlobalEventHandlers, ev: Event) => any'.
Types of parameters '__0' and 'ev' are incompatible.
Type 'Event' is not assignable to type '{ target: HTMLInputElement; }'.
Types of property 'target' are incompatible.
Type 'EventTarget | null' is not assignable to type 'HTMLInputElement'.
Type 'null' is not assignable to type 'HTMLInputElement'.
469 input({
~
470 placeholder: "Enter username",
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
473 (inputState.val = target.value),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
474 }),
~~~~~
|
Makes sense since it was typed as |
This change is breaking other's people code. Is there a way to avoid it ? |
Can you review the PR #109 ? |
It's not technically breaking their code, but their code may not typecheck after upgrading. But the point of this PR is to use correct types. If you want to use semver for TypeScript types, the best solution would be to include this change in a future major release. |
If someone updates to a new version and the build fails, it is a breaking change. |
@FredericHeem No, TypeScript uses |
In the case of input of type text, the event type is input({
type:"text"
oninput: (event: InputEvent) => console.log(event.data),
}), |
There are no specific types in the TypeScript DOM lib for a You would have to use input({
type:"text"
oninput: (event) => console.log((event as InputEvent).data),
}), You could probably hack your way around this but it would introduce very complicated types and it's not worth the effort in my opinion. It is better to wait until TypeScript catches up (if it will). There is also a chance the HTML standard will be modified whatwg/html#682 |
I have yet to see any benefit of this approach. Moreover that will break existing code. |
Automatic types for I can see if I can think of a backward-compatible approach. |
Now
will have the correct type for
e
(and notany
).I removed the other types in the
PropsHTMLElement
union since they are duplicated inProps
.