3 ms·
Thank you for your response. This Left and Right declaration style was a new one for me. Also, homogeneous map wasn't exactly a familiar concept. I don't remem
by jarpineh 8y ago
Thank you for your response.
This Left and Right declaration style was a new one for me. Also, homogeneous map wasn't exactly a familiar concept. I don't remember meeting these when learning TypeScript and dabbling with Elm. I fear I don't quite grasp the type structure here yet. I can go forward with my testing based on your example.
- KirinDave 8y agoBy the way, it's entirely fair game for you to create config/domain specific things and not simply (Left|Right) dichotomies. And by the way, TypeScript DOES have a form of Sum typing like that as of 2017! You can say something like this from the manual: type Shape = Square | Rectangle | Circle | Triangle; function area(s: Shape) { switch (s.kind) { case "square": return s.size * s.size; case "rectangle": return s.height * s.width; case "circle": return Math.PI * s.radius ** 2; } // should error here - we didn't handle case "triangle" } (You can see more about it here: https://www.typescriptlang.org/docs/handbook/advanced-types.html https://www.typescriptlang.org/docs/handbook/advanced-types...., search for "Discriminated Unions".) You can also make these ad-hoc ,and they're useful for harnessing underlying functions that might return null from stdlibs. E.g., function strToInt( x: string ): number | null And then you're required to check for nulls and the compiler will complain if you don't check for them. Pretty useful!