Skip to content

Detect uncalled functions that appear in void expressionsΒ #47699

Open
@mjbvz

Description

@mjbvz

Suggestion

πŸ” Search Terms

  • uncalled function
  • check
  • statement

⭐ Suggestion

Today TS can detect uncalled functions that appear in conditionals. I propose also extending this to detect uncalled functions that appear an an expression where the result is unused

πŸ“ƒ Motivating Example

export interface Foo {
    doImportantStuff(): void;
}

declare const foo: Foo;

if (foo.doImportantStuff) { // This one is detected
  ...
}

[foo].forEach(x => foo.doImportantStuff);  // Mistake here. The user forgot to call `doImportantStuff`

πŸ’» Use Cases

This was inspired by a real world bug in the VS Code codebase. The case with forEach shows the problem we ran into

Off the top of my head, I don't think there would be false positives but may need some more thought to make sure

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions