1

I have an interface Iphone

export interface Iphone {
    url: string;
    name: string;
    year: number;
    color: string;
    number_of_cameras: number;
    popularity: boolean;
    quantity: number;
} 

Can I somehow make it that color can only be 'black', 'blue' and 'light'? Something like that

color = { 'black' | 'blue' | 'light' }
  • 3
    `color: 'black' | 'blue' | 'light';`? – jonrsharpe Jul 13 '22 at 13:11
  • It's well-worth your time to read through [the handbook](https://www.typescriptlang.org/docs/handbook/intro.html). It doesn't cover everything, and it covers things very lightly, but it covers most stuff. You'd find string unions in there, for instance. :-) – T.J. Crowder Jul 13 '22 at 13:15

0 Answers0