Skip to content

(0, object.property)() produces TS2695 #35866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dead-claudia opened this issue Dec 27, 2019 · 4 comments · Fixed by #51989
Closed

(0, object.property)() produces TS2695 #35866

dead-claudia opened this issue Dec 27, 2019 · 4 comments · Fixed by #51989
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Milestone

Comments

@dead-claudia
Copy link

TypeScript Version: 3.0.0-dev.201xxxxx

Search Terms: Left side of comma operator is unused and has no side effects

(This only brought 7 results in total at the time of writing.)

Code

let list = [() => { }];
(0, list[0])();
let object = {fn: () => { }};
(0, object.fn)();

Expected behavior: It to type-check without errors - this is a common idiom to invoke functions without setting this to the property it's on, and it's fairly broadly used.

Actual behavior: TS2695: Left side of comma operator is unused and has no side effects on both calls

Playground Link: https://www.typescriptlang.org/play/index.html?ssl=3&ssc=11&pln=3&pc=5#code/DYUwLgBMCWDOkF4IG0AUBKCCB8EDeEAvgLoDcAUKgAwA0UcYyVx6GFokA9gEYBWIAY0T4AZgDsAXBAxZcBQoQrU6PfkIB041ulJA

Related Issues: #12978 #33646

@ilogico
Copy link

ilogico commented Dec 27, 2019

void 0 :)

ajafff added a commit to ajafff/TypeScript that referenced this issue Dec 27, 2019
@ajafff
Copy link
Contributor

ajafff commented Dec 27, 2019

Fix is up at #35878

@DanielRosenwasser DanielRosenwasser added In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Jan 7, 2020
@MattShaile
Copy link

Any chance we can get this PR merged?

@andrewbranch andrewbranch added this to the Backlog milestone Oct 4, 2021
@shicks
Copy link
Contributor

shicks commented Dec 21, 2022

The PR was dropped because the author seemed to have abandoned it. I'd be willing to push it through if there's interest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants