I'm trying to make something typesafe and I'm not 100% sure if it's possible:
If I have an array of "services", where a Service is defined as:
interface Service {
id: string;
dependencies?: [string] // refs to others Service.id's
}
Is there a way to make the dependencies array typesafe? To illustrate:
import { Service } from './service.ts';
const services: Service[] = [
{
id: "authors",
},
{
id: "comments",
}
{
id: "posts",
dependencies: [] // <-- type this as `Array<"authors | "comments">`
}
]