Skip to content

Optional Chaining does not propagate receiver when parenthesized #35476

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
jridgewell opened this issue Dec 3, 2019 · 2 comments · Fixed by #35494
Closed

Optional Chaining does not propagate receiver when parenthesized #35476

jridgewell opened this issue Dec 3, 2019 · 2 comments · Fixed by #35494
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@jridgewell
Copy link

TypeScript Version: [email protected]

Search Terms:
optional chaining receiver call parentheses

Code

const foo = { bar() { return this } };

console.assert(foo === (foo?.bar)());

Expected behavior:

foo should be propagated as the receiver to the foo.bar method call.

Actual behavior:

No receiver is propagated (due to the ternary breaking the receiver).

Playground Link: https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=4&pc=1#code/MYewdgzgLgBAZiEMC8MDeMBGBDATgCgEp0ZcBTKAV1zBigAsBLCGAXzYG4AoL0SEADZkAdNggQyuKPgRJk8mDMQB+YTlyEihDkA

Related Issues:

@ajafff
Copy link
Contributor

ajafff commented Dec 4, 2019

Fix is up at #35494

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Dec 5, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.8.1 milestone Dec 5, 2019
@RyanCavanaugh
Copy link
Member

@rbuckton please take a look at the linked PR. Thanks!

@RyanCavanaugh RyanCavanaugh added the Rescheduled This issue was previously scheduled to an earlier milestone label Aug 31, 2020
rbuckton pushed a commit to ajafff/TypeScript that referenced this issue Mar 4, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants