Every story and comment from the Hacker News API, in a layout borrowed from 2001.
A comment on Rewriting TypeScript in Rust? You'D have to be. Parent comment
type Shape = Square Int | Circle Int
print (Square size) = .. print (Circle radius) = ...
type Shape = { type: 'square', size: number } | { type: 'circle', radius: number }
function print(shape: Shape) { if (shape.type === 'square) { ... } else if (shape.type === 'square) { ... } }
It also have some pitfalls, e.g. you can write:
print({type: 'square', size: 10});
const x = {type: 'square', size: 10}; print(x); <-- type error
const x = {type: 'square' as const, size: 10}; print(x);
There are no comments on this comment yet.
It also have some pitfalls, e.g. you can write:
But you cant write: You have to write: Things like this just complicates the type system and type inference.