4 ms·
Not just that, the initial Flow example can actually be translated 1-to-1 to TypeScript (without using enums at all): https://www.typescriptlang.org/play/index
by pluma 9y ago
Not just that, the initial Flow example can actually be translated 1-to-1 to TypeScript (without using enums at all):
https://www.typescriptlang.org/play/index.html#src=type%20AppScreen%20%3D%0D%0A%20%20%7C%20'LoadingScreen'%0D%0A%20%20%7C%20'CodeEntryScreen'%0D%0A%20%20%7C%20'SuccessScreen'%0D%0A%20%20%7C%20'FailureScreen'%3B%0D%0A%0D%0Aconst%20impossible%20%3D%20(value%3A%20never)%3A%20never%20%3D%3E%20%7B%0D%0A%20%20throw%20new%20Error('This%20case%20is%20impossible.')%3B%0D%0A%7D%0D%0A%0D%0Aconst%20needsCancelButton%20%3D%20(screen%3A%20AppScreen)%3A%20boolean%20%3D%3E%20%7B%0D%0A%20%20switch%20(screen)%20%7B%0D%0A%20%20%20%20case%20'LoadingScreen'%3A%0D%0A%20%20%20%20%20%20return%20true%3B%0D%0A%20%20%20%20case%20'CodeEntryScreen'%3A%0D%0A%20%20%20%20%20%20return%20true%3B%0D%0A%20%20%20%20case%20'SuccessScreen'%3A%0D%0A%20%20%20%20%20%20return%20false%3B%0D%0A%20%20%20%20default%3A%0D%0A%20%20%20%20%20%20%2F%2F%20TypeScript%20error%3A%0D%0A%20%20%20%20%20%20%2F%2F%20Argument%20of%20type%20'FailureScreen'%20is%20not%20assignable%20to%20parameter%20of%20type%20'never'.%0D%0A%20%20%20%20%20%20return%20impossible(screen)%3B%0D%0A%20%20%7D%0D%0A%7D https://www.typescriptlang.org/play/index.html#src=type%20Ap...