Skip to content

TS6133 'myparam' is declared but its value is never read: Relax for empty function bodies #26229

@benny-medflyt

Description

@benny-medflyt

Suggestion

Sometimes developers create a base class that has methods that have an empty implementation and are meant to be (optionally) implemented by child classes. This is sometimes called the "strategy pattern".

Here is an example:

export abstract class WidgetObserver {
    onResized(width: number, height: number): void {}
    onTextChanged(text: string): void {}
    onDestroyed(): void {}
}

The problem is that in TypeScript we will get 3 errors:

TS6133 'width' is declared but its value is never read
TS6133 'height' is declared but its value is never read
TS6133 'text' is declared but its value is never read

Most of the time this error is useful, since it can help reveal bugs that resulted from us forgetting to use a particular parameter, or even help us redesign our code if we realize that a parameter is not actually needed.

But for the case where the function body is empty, this error is not helpful, there is no possibility that the programmer forgot to do something, and it should be clear to the compiler that the programmer knows what they are doing.

In addition to the "strategy pattern" there are a few other patterns of functions with empty bodies.

Summary: I suggest that error TS6133 should be completed suppressed for function parameters if the function body is empty.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript / JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. new expression-level syntax)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions