4 ms·
Thanks for this write-up. What about ADTs and pattern matching? Afaik, they are not available in Typescript and the emulations that I've seen are very sloppy.
by forkerenok 6y ago
Thanks for this write-up. What about ADTs and pattern matching?
Afaik, they are not available in Typescript and the emulations that I've seen are very sloppy.
- paavohtl 6y agoTypeScript supports ADTs (discriminated unions) and not-quite-pattern matching using a combination of features: union types, literal types and control-flow based type narrowing. Here's an example from the TS handbook: https://www.typescriptlang.org/docs/handbook/unions-and-intersections.html#discriminating-unions https://www.typescriptlang.org/docs/handbook/unions-and-inte.... What you need to understand about TypeScript is that it ultimately is just JavaScript. After TS 2.0 a decision was made that TS will align with standard EcmaScript and will not implement any* run-time features not part of the ES standard or ES proposals. Because of this decision TypeScript cannot have a proper dedicated pattern matching syntax until JavaScript gets one. TypeScript does support some pattern matching using ifs and switch statements and other control flow structures, but that's as good as it gets until JS improves as well.
- Garlef 6y agoHere's what I use: https://github.com/gbegher/groth/blob/460852a71859f149ecf9b5154af65eb958f869f5/src/Core/Sum.ts https://github.com/gbegher/groth/blob/460852a71859f149ecf9b5... Did not cause any roadblocks so far.