Skip to content
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

First Argument in Function.prototype.call should be optional #44530

Closed
jonath92 opened this issue Jun 10, 2021 · 3 comments
Closed

First Argument in Function.prototype.call should be optional #44530

jonath92 opened this issue Jun 10, 2021 · 3 comments

Comments

@jonath92
Copy link

🕗 Version & Regression Information

Occurs in the latest Version (4.3.2) and nightly version

💻 Code

Function.prototype.call combined with Optional Chaining is a nice way to only call a method if the method is defined (see this thread).

foo?.call()

🙁 Actual behavior

Ts complains: Expected at least 1 arguments, but got 0

🙂 Expected behavior

I expect that this works as the first argument is actually optional according to Mozilla and own observations.

@jonath92 jonath92 mentioned this issue Jun 10, 2021
@MartinJohns
Copy link
Contributor

Function.prototype.call combined with Optional Chaining is a nice way to only call a method if the method is defined

Am I missing something weird here? You can do that with the ?.() operator as well.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#optional_chaining_with_function_calls

@jonath92
Copy link
Author

I didn't know that. This is indeed much better as you don't loose IntelliSense that way. Thanks. But this is a Bug anyway (also not very important tbh) :-)

@MartinJohns
Copy link
Contributor

It's not explicitly mentioned, but #27028 seems to me more like it's a design decision, not a bug. Calling .call() without a thisArg rarely makes sense, and in these few cases you can just pass undefined along.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants