microsoft / microsoft/TypeScript
Should disallow using the result of calling a void-returning function
Nobody has claimed this yet.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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