I have a simple union type of string literals and need to check it\'s validity because of FFI calls to \"normal\" Javascript. Is there a way to ensure that a certain variabl
using type is just Type Aliasing and it will not be present in the compiled javascript code, because of that you can not really do:
MyStrings.isAssignable("A");
What you can do with it:
type MyStrings = "A" | "B" | "C";
let myString: MyStrings = getString();
switch (myString) {
case "A":
...
break;
case "B":
...
break;
case "C":
...
break;
default:
throw new Error("can only receive A, B or C")
}
As for you question about isAssignable, you can:
function isAssignable(str: MyStrings): boolean {
return str === "A" || str === "B" || str === "C";
}