3 ms·
While it's easier to use discriminated unions with some "type" field (easier to use switch/case) here's the reality: 1. There's many ways for the compiler to n
by __ryan__ 4y ago
While it's easier to use discriminated unions with some "type" field (easier to use switch/case) here's the reality:
1. There's many ways for the compiler to narrow a union type [0]
2. There's a better solution than depending on "easy" narrowing for excessively large union types: type guards, callback registry, etc.
[0]: https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgAgILIN4ChnLgWQgGci4BzCALmRAFcBbAI2gG4sBfLLUSWRFAEKYcyRoRLkqyImCigybTt3DR4SZAGFhuBONIVqjAPZGANhDghFXMAE8ADij2TkAXjTIAPsiHeNbLBhaEAQwYCMQZEgZAAp6Yn0pZwoASm1kYBhkGIAiAgTJHIzI+IlU9J0ImWQANzhTWik6Jmg3ZFLEgDp8sog2XEqQIjMITtMjMlyexOocgBpa+saU-uR2ZAhTIhRM7JyxAooi0HbDiDTsAeQEKrBFhqkZORAyNo7JToPe1cHh8zGJrkvjNkPN7stVutNtsKtdbuCpMYRpY3mdOrozj84UMRgDJjkMb1Zgs6g8ViJOEogA https://www.typescriptlang.org/play?#code/JYOwLgpgTgZghgYwgA...