1

I trying to call a a function inside a array. I get an error message : The expression type { function } is not assignable to boolean.

Declaration:

    public conditions: { (value: any): bool; }[] = [];

Usage:

    var myBool: bool = conditions["myKey"]("someParam");


Whats wrong here ? Do i need to cast here ?

3
  • 1
    Which version of typescript are you using? They changed several things since release and I am asking, because var conditions: { (value: any): bool; }[] = []; var myBool: bool = conditions["myKey"]("someParam"); compiles fine for me. Commented Mar 27, 2013 at 15:36
  • 0.8.3 using Webstorm 6 (its more restricted, what is not bad at all) Commented Mar 27, 2013 at 15:37
  • interesting, I am using an older version (0.8.1.1) with visual studio ... will upgrade to 0.8.3 to test it. Commented Mar 27, 2013 at 15:43

1 Answer 1

1

This works in the TypeScript playground, which uses 0.8.3. Are you sure this is actually the code in question? Indexing an array by a string produces a value of type any, so the function invocation there is sort of irrelevant for type purposes since it will just produce an any as well.

Sign up to request clarification or add additional context in comments.

Comments

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.