-
Notifications
You must be signed in to change notification settings - Fork 222
Add new type parameters to functions where possible #3349
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
Conversation
We're still not verifying the actual object returned by JSON.parse so this isn't any safer at runtime than using 'any', but it helps add more static typing to the code calling readJsonlFile.
| * @param telemetry The telemetry listener to use for error reporting. | ||
| */ | ||
| export function registerCommandWithErrorHandling( | ||
| export function registerCommandWithErrorHandling<S extends unknown[], T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's annoying that registerCommandWithErrorHandling gained two args, but thankfully in all the cases we use it the types are inferred so we don't need to do anything. In reality in both uses the type could be () => void, so I wouldn't be against just hardcoding that here for simplicity, and we can revisit later if this function needs to handle more complex functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy either way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had another go at this and condensed the two type args into one. I don't know why I didn't do this before. Maybe it didn't work before and some other change made it possible, or maybe I just didn't do it properly.
I think this is a better solution overall and makes things clearer.
| * @param telemetry The telemetry listener to use for error reporting. | ||
| */ | ||
| export function registerCommandWithErrorHandling( | ||
| export function registerCommandWithErrorHandling<S extends unknown[], T>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy either way
These are a few functions that currently use
anybut could instead have a type parameter.I think each of these cases increases our type safety a little bit. I can't see any downsides, unless I've missed an edge case.
Checklist
ready-for-doc-reviewlabel there.