question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proper Typing for Events

See original GitHub issue

Summary 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:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
zackdotcomputercommented, Apr 25, 2021

@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.

1reaction
zackdotcomputercommented, Apr 2, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found