top | item 47078506

(no title)

throw-the-towel | 10 days ago

IDK, I still miss Rust's strictness and exhaustive enum matching.

discuss

order

socalgal2|10 days ago

I don't know about what other strictness you're referring to but exhaustive enum matching is common check in most TS stacks via eslint. Yea, it's not builtin, just saying there's a solution and it's super common.

rtpg|10 days ago

The thing you gotta make sure to do is basically return inside of switch statements. Typescript will gladly propagate a type that you think is never but is actually ThatOneCaseYouForgot if it's not ever used or referred to.

Every TS project I've worked on has an assertNever(val) thing specifically to check for this kinda stuff

cyberax|10 days ago

You can actually have it built-in (via default case in 'switch' statements having a 'never()' statement). But it's less powerful than Rust's.

tcfhgj|10 days ago

last time I researched enums in TS for a project, they were a mess such that it was better not to use enums in the first place

ceteia|10 days ago

Enum matching is one of the better aspects of Rust.