Nick Heiner
Nick Heiner

Reputation: 122450

Is @typescript-eslint/no-invalid-void-type universally applicable?

I'm looking at enabling the lint rule @typescript-eslint/no-invalid-void-type. I want to make sure everything it's flagging is truly something I always want to get rid of. Just to check my understanding. Are the following statements correct?

  1. There's never any reason to include void in a type union, like string | void.
  2. There's never any reason to declare a function that takes void as a param. (Except for something like this: void).
  3. There's never any reason to put void in a container generic, like Array<void | string>.
  4. Putting void | undefined on a function return signature (e.g. () => void | undefined) is redundant.
  5. If you have () => SomeType | void, you should use () => SomeType | undefined instead.

And the reason for most of those statements being true is that you can't instantiate a value of type void, so something like Array<string | void> makes no sense. Right?

Upvotes: 2

Views: 1697

Answers (1)

Ronan-Yann Lorin
Ronan-Yann Lorin

Reputation: 331

I add to disable this rule on the following code fragment which looks correct to me:

  register<T>(
    requestFunction: (reqId: number) => void,
    cancelFunction: (reqId: number) => void | null | undefined, // eslint-disable-line @typescript-eslint/no-invalid-void-type
    ...

Upvotes: 0

Related Questions