1

Pretty straightforward question, not sure what I've got wrong syntactically here.

const options: object[] = [
    { value: 0, label: 'Ab' },
    { value: 1, label: 'A' },
    { value: 2, label: 'Bb' },
    { value: 3, label: 'B' },
    { value: 4, label: 'C' },
    { value: 5, label: 'Db' },
    { value: 6, label: 'D' },
    { value: 7, label: 'Eb' },
    { value: 8, label: 'E' },
    { value: 9, label: 'F' },
    { value: 10, label: 'Gb' },
    { value: 11, label: 'G' }
]
console.log(options[1].value)

1 Answer 1

2

You need to define an interface for the objects:

interface Item { value: number, label: string };

const options: Item[] = [
...
Sign up to request clarification or add additional context in comments.

1 Comment

Ah, that makes sense. That's how TypeScript knows what properties (and their types) should be in an object. Thanks!

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.