I'm currently working on a project where I need to ensure type safety, but I'm unsure if it's achievable:
Suppose I have an array of "services", with each service defined as follows:
interface Service {
id: string;
dependencies?: [string] // references to other Service.id's
}
Is there a method to enforce type safety for the dependencies
array? For example:
import { Service } from './service.ts';
const services: Service[] = [
{
id: "authors",
},
{
id: "comments",
}
{
id: "posts",
dependencies: [] // <-- specify this as `Array<"authors" | "comments">`
}
]