3

Why is this illegal in TypeScript?

interface numarr {
    [i : number] : number;
}

var p : numarr = [3,6,8];

The compiler says "Cannot convert 'number[]' to 'numarr'."

I'm afraid I've misunderstood something quite basic here. I thought the point of the above interface was to describe an array of numbers indexed by numbers, which is exactly what [3,6,8] is.

0

2 Answers 2

3

You can alternatively use the following syntax, if I didn't get you wrong.

var arr : number[] = [3, 6, 8];
Sign up to request clarification or add additional context in comments.

Comments

1

I asked this question in 2013. It is no longer relevant. The code in my question is now accepted by the compiler.

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.