microsoft / microsoft/TypeScript

Should disallow using the result of calling a void-returning function

Open
#40,997 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 4.1.0-dev.20201008

Search Terms: disallow function call void return usage warn error

Code

function doesntReturn() {
    // no return statement
}

const foo: string = doesntReturn() + 'foo'; // should be an error

Expected behavior:

The expression doesntReturn() + 'foo' should be an error because it uses the value of a void-returning function call. As far as I can tell, there is literally no good reason to use the return value of a function with no return statements like this.

This is similar to the current behavior of disallowing void-returning expressions inside control flow (issue #26262). It is also similar to the reasoning behind the warning that occurs when using a function value (instead of calling it) in an if condition.

Actual behavior:

No error message is given.

Playground Link: here

Related Issues: #26262

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Playground example to reproduce the missing diagnostic, then read related issue #26262 for the comparable control-flow behavior. Done means the expression that uses the result of a void-returning function call reports an error, while the existing example continues to behave as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.