I have a type set to the following:
export type Foo = 'A' | 'B' | 'C' | 'D' | 'E';
I then set a variable in an interface to have an array of this type, like so:
export interface IBar {
id: string;
letters: Foo[]
}
Then I try to create an array with the previous values of letters and a new value i.e.
const chosenLetter = 'B';
...
const { letters } = IBar;
const allLetters = [...letters, chosenLetter];
But I’m getting an error saying that the type is wrong and that Foo[] must have an iterator. I’m quite new to Typescript so all feed back is welcome.
I tried setting the type to Foo[] i.e. const allLetters: Foo[] = [...letters, chosenLetter];
.
Jake is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.