How can I type a string to be within one of the static IDs in a hardcoded array called storage using const storage : Readonly<{id: string}[]>? The array will remain unchanged during runtime.
I attempted (typeof storage)[number]['id'] but it only returns a string. I also tried satisfies Readonly<{id:string}[]>.
interface HasID {
id: string
info?: any
}
const storage : Readonly<HasID[]> = [
{ id: 'foo' },
{ id: 'bar', info: ['baz'] }
]
const storage2 = [
{ id: 'foo' },
{ id: 'bar', info: ['baz'] }
] satisfies Readonly<HasID[]>
let str // aiming to type this as "foo" | "bar"
type StorageID = (typeof storage)[number]['id'] // string
type StorageID2 = (typeof storage2)[number]['id'] // string