3 ms·
Why not just use an Enum? It will only accept the values of that enum. https://www.typescriptlang.org/docs/handbook/enums.html#enums https://www.typescriptlang
by no_wizard 7y ago
Why not just use an Enum? It will only accept the values of that enum.
https://www.typescriptlang.org/docs/handbook/enums.html#enums https://www.typescriptlang.org/docs/handbook/enums.html#enum...
https://www.typescriptlang.org/play/index.html?useDefineForClassFields=true&preserveConstEnums=true#code/KYOwrgtgBAsgngZQC4CcCWIDmBnKBvAWACgpSoAxAeUqgF4oAiAIwEMUGAaYsqAIQEEASnUYAzAPbjO3MlUoDh9BhPGt2xAL7FiosCADGSNOJBQTAGzgBRcBH4pMACgBuLcwC5YiVBhwBKfBlSfRNscXNgADpzcScGJAALNFwAdzRzczMQSygkFgBrYCyi8VFchKLCuFxRFHFoeGR0LGwGPwBuIKgQkDCI6NiXNzpaekafFsiFDs1tIgtrW3s4xOSoNIyoJiKWU2AUOvYZ+ezFyGXHceacKaEAgHpHqAAVJNw1kHEkKF2ofcOgA https://www.typescriptlang.org/play/index.html?useDefineForC...
- untog 7y agoJust my personal preference but using these string union types means that you don’t have to import the enum. Plus it’s less verbose and translates back to JS better than an enum does. Really just a matter of preference though.