0

Suppose I know that I have array like ['string', 10, true];. Is there a way to write an interface for it? I know there's globally indexed interface:

interface IEntry {
    [i:number]:string;
}

But typing the following is not working:

interface IEntry {
    [0]:string;
    [1]:number;
    [2]:boolean;
}

1 Answer 1

3

Yes. Typescript tuples.

type Entry: [string, number, boolean];

var entry: Entry = ['foo', 1, false]; 
var exit: Entry = ['bar']; // tsc error
Sign up to request clarification or add additional context in comments.

1 Comment

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.