Using a readonly array as a type in TypeScript

This is a pretty useful feature where you can have a readonly array act as a type in TypeScript. I always forget how to do it so I'm keeping a note of it here:

const myArray = ['apple', 'banana', 'orange'] as const;

// type MyType = "apple" | "banana" | "orange"
type MyType = typeof myArray[number];