1

Why do I have to cast function into Function type to be able to access apply and other members?

var a: Function = () => {};
a.apply(); // works

var a = () => {};
a.apply(); // does not work

How should I do it with these functions?:

function a(){}
a.apply(); // does not work

1 Answer 1

1

If you pass the "this" argument to the apply function, it seems to work either way:

var a = () => {};
a.apply(null);

var b: Function = () => {};
b.apply(null);
Sign up to request clarification or add additional context in comments.

2 Comments

Interesting. It works but the intellisense for apply does not work. Do you observe the same and is it not a bug?
I think this is deliberate. It doesn't suggest apply in the intellisense list, but if you type apply( it is aware of it and hints at the required arguments. I can't speak on behalf of the TypeScript team - but I think this could be deliberate. The same is true of call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.