Proper Typing for Events
See original GitHub issueSummary of proposed feature
Since the arguments to each event in the events
object are known, the typing should include that information.
Purpose of proposed feature
To making coding easier and prevent errors when using events
Detail about proposed feature Currently the events object has the following typing:
export type EventCallback = (message: any) => Promise<void>;
export type EventsOptions = Partial<Record<EventType, EventCallback>>;
I think it should have an actual shape defining the event names supported and their message types. As an example:
export type EventCallback<MessageType = any> = (message: MessageType) => Promise<void>;
type SignInMessage = {
user: User;
account: Record<string, unknown>;
isNewUser?: boolean;
};
export type EventsOptions = Partial<{
signIn: EventCallback<SignInMessage>;
// And so on...
}>;
Potential problems I don’t foresee any issues with this. The only thing I’m unsure about is if your .d.ts files are autogenerated or manually written.
Please indicate if you are willing and able to help implement the proposed feature. Of course, just let me know if your .d.ts files are autogenerated or manually written.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
React and TypeScript: How to find the right event type
In this article, you'll learn how to find the correct TypeScript interface for React events in any situation.
Read more >Forms and Events - React TypeScript Cheatsheets
So React.ChangeEventHandler<> is simply a "blessed" typing by @types/react , whereas you can think of the inferred method as more... artisanally hand-rolled.
Read more >Introduction to Keyboard Events in JavaScript - Section.io
In this article we will learn about what keyboard events are, and explore different keyboard events. We will also build a simple game...
Read more >Typescript and React: What is the proper type for an event ...
Specifically, I am unable to use object destructuring with my handleClick() function that goes on the onClick={handleClick} attribute. This is ...
Read more >React events and TypeScript: a complete guide - Devtrium
Events are everywhere in React, but learning how to properly use them and their handlers with TypeScript can be surprisingly tricky.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@balazsorban44 That’s great! I’ve been pretty busy with a new puppy 🐶 but managed to sneak a PR in during one of her naps.
Sorry - just saw your note on the npm package page that typing issues should be directed to DefinitelyTyped. Maybe the .d.ts files in this project should be removed?
Moving my issue over to them.