Currently, I am exploring ways to enhance either GenericActionables
or Items
in a way that eliminates the need to manually add the API method name as a
GenericActionables<"nameOfNewMethod">
to the Actionables
type every time. Any suggestions on how to achieve this synchronicity are welcome. Thank you :)
interface API {
playSound: (id: string, volume: number) => void,
playPool: (id: string, randomize: boolean) => void
}
type GenericActionables<T extends keyof API> = {
method: T,
params: Parameters<API[T]>
}
// Looking for an improved approach to defining Actionables
// so that it automatically aligns with any updates to the API
type Actionables =
GenericActionables<"playSound"> |
GenericActionables<"playPool">
export const actionables: Actionables[] = [
{method: "playSound", params: ["quack", 0.8]}, // this should work
{method: "playSound", params: ["quack", true]}, // this should NOT work
{method: "playPool", params: ["smack", true]}, // this should work
{method: "playPool", params: ["smack", 0.8]}, // this should NOT work
]