I have a dictionary of shape:
const map = {
SCOPE:{
ACTION:{
"default": string,
"mac"?: string
}
}
}
Where "SCOPE" is a finite amount of strings and "ACTION" another finite amount of strings, different for each scope.
And a React component of signature:
export function GodotShortcut({ scope = "general", type }){
}
It's important that the default scope is "general", because it will be by far the most used. The only mandatory property is therefore type, which should be restricted base on the scope.
I am managing to type an interface that does what I want:
GodotShortcut({type:"close scene"}) // works, "close scene" exists in the "general" scope
GodotShortcut({type:"continue"}) // error, "general" doesn't have a "continue"
GodotShortcut({scope:"debugger", type:"continue" }) // works, "continue" exists in the "debugger" scope
GodotShortcut({scope:"debugger", type:"select" }) // error, "debugger" doesn't have a "select"
My issue is that I am not managing to get the proper type inside the function. Of course, I could just shrug and use any, but I would like to understand what I'm doing wrong here. Ideally, it'd all type correctly without type coercion