1

How can I create an interface for an array that accepts both numbers and strings?

Since inside the function [1,'1'], ['1','1'],[1,1] are equivalent (they are joined inside as '1.1'), I can't seem to satisfy the compiler. It gets me TS2087: Could not select overload for 'call' expression.

works for fn([1,1]); and fn(['1','1']); but not mixed values.

1
  • Nope, no algebraic types. Commented Jul 29, 2014 at 22:44

1 Answer 1

2

It's not possible. I suggest to use any[]:

function fn(arr: any[]) {
    alert(JSON.stringify(arr));
}
fn([1, 1]);
fn(['1', '1']);
fn(['1', 1]);
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.