Is there a way to represent the following logic in TypeScript?
type LanguageName = "javascript" | "typescript" | "java" | "csharp"
type LanguageToWasmMap = {
[key in LanguageName]: Exclude<LanguageName, key>
}
//I need this assignment to be successful
const languageNameToWasmNameMap: LanguageToWasmMap = {
"javascript" : "typescript"
}
//I want this assignment to throw an error
const languageNameToWasmNameMapWithUndefined: LanguageToWasmMap = {
"javascript" : undefined
}
Try it out on Typescript playground : Click Here
Upon further consideration, it seems logical to make the LanguageToWasmMap optional and perform a runtime check for undefined values.