Imagine I have a structure like this:
export interface MyObject {
id: number
title: string
}
and then I create an array as shown below:
const myArray: MyObject[] = [
{
id: 2358,
title: 'Item 1'
},
{
id: 85373,
title: 'Item 2'
}
]
Is there a way to define a type that restricts values to only those ids in the array? For instance, something similar to:
type DesiredType = 2358 | 85373
Check out this Codewich link where different attempts were made but didn't work as expected.