4 ms·
I am absolutely blown away at how good TypeScript's type checker is, given how much of an unholy mess JavaScript is, and that the TypeScript language cannot jus
by Waterluvian 5y ago
I am absolutely blown away at how good TypeScript's type checker is, given how much of an unholy mess JavaScript is, and that the TypeScript language cannot just deprecate all the awful parts.
More than once I've yelled at my screen, "HOW DO YOU KNOW THIS?!" about some inferred or narrowed type.
- dmitriid 5y agoHowever, more than once I've also yelled "HOW DO YOU NOT KNOW THIS?!" at something or other :)
- reuben364 5y agoI've managed to get the compiler to typecheck const x: Thing = exprA; const y: Thing = exprB; const z = [x, y]; but somehow not: const z: Thing[] = [exprA, exprB]; although exprA and exprB were pretty nasty typing wise.
- epolanski 5y agoJust today I was triggered that this compiles. declare foo: never[] // it can only be an empty array foo[1] // compiles TypeScript is a nice type system, it's surprisingly expressive and flexible, like e.g. in Haskell I was surprised that there's this strange notion that for a given type you can only have one `Eq` or `Ord` instance for some type A. But in TypeScript you can have as many Ord interfaces as you want. I may want to order some `User` type by last login, first login or whatever I want, but in Haskell you need to overcomplicate it and create a newtype.
- Jenk 5y agoI wouldn't expect never[] to mean 0 length array, tbf. It's a variable length array of _type_ never. It should be something akin to: declare foo: never[0];
- endgame 5y ago> you can only have one `Eq` or `Ord` instance for some type A. This is a good thing - it stops you from using one Ord instance when putting As into a Map or Set, and then trying to pull them back out using another. Newtypes let you provide "additional" instances in a safe way.
- epolanski 5y agoWhy shouldn't I be able to use as many Ord instances as I want? I'll give you a trivial example I have some data type representing a TvShow, why should there be just one way to sort a collection of TvShow? Maybe I want to sort by year, maybe by length, maybe by category. It's trivial to do in fp-ts, you can have as many Ord instances as you wish.
- hiptobecubic 5y agoThey just said why it's important to explicitly track which instance is in effect and newtypes do that.
- Nullabillity 5y ago
- rowanG077 5y agoI'm the opposite. I was continually perplexed by trivial stuff that TypeScript just couldn't figure put. Maybe that has changed in the last year but I doubt it.
- lockyc 5y agoDo you have examples?
- smt88 5y agoIn my 5+ years introducing TypeScript everywhere that my team has to use JavaScript, this is almost always because JavaScript is an insane language that allows many counterintuitive things. TS is sometimes weird because it is a superset of JS and has to be compatible.