Skip to content

Conversation

@robertbrignull
Copy link
Contributor

These are a few functions that currently use any but 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

  • CHANGELOG.md has been updated to incorporate all user visible changes made by this pull request.
  • Issues have been created for any UI or other user-facing changes made by this pull request.
  • [Maintainers only] If this pull request makes user-facing changes that require documentation changes, open a corresponding docs pull request in the github/codeql repo and add the ready-for-doc-review label there.

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.
@robertbrignull robertbrignull requested a review from a team February 13, 2024 11:24
@robertbrignull robertbrignull requested a review from a team as a code owner February 13, 2024 11:24
* @param telemetry The telemetry listener to use for error reporting.
*/
export function registerCommandWithErrorHandling(
export function registerCommandWithErrorHandling<S extends unknown[], T>(
Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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>(
Copy link
Contributor

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

@robertbrignull robertbrignull merged commit 923a480 into main Feb 13, 2024
@robertbrignull robertbrignull deleted the robertbrignull/add_types branch February 13, 2024 14:02
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.

5 participants