3 ms·
Can you give a concrete example of the kind of code you'd like to write that you can't write in Typescript? Types absolutely are a first class citizen in TypeS
by piazz 6y ago
Can you give a concrete example of the kind of code you'd like to write that you can't write in Typescript?
Types absolutely are a first class citizen in TypeScript. Especially coming from Go, which doesn't even support generics, Typescript is really quite powerful. It even has support for ADTs via discriminated unions, which gives you the same power of enums with associated types that you'd get in Rust/Swift.
Is it possible the reason you feel like Typescript doesn't have Types as a first class citizen is because it leverages structural typing rather than nominal typing?
- mxz3000 6y agoNot op, but I have experience with TS and some things are more difficult than they should be. For me the biggest issue is the lack of typesafe deserialisation. This makes it super painful to do IO (of which there's _a lot_ of in the serverless infrastructure I'm currently working on). While you can validate with a manually written type guard, that's a pain... It would great if you could do JSON.parse<T>() and have TS auto-generate the type guard for you... There's also no easy way to switch on union types (à la ocaml), sure you can define an enum and use a JS switch, but that's not as nice, and enforcing exhaustiveness of the switch requires some type hackery with `never`...
- mixedCase 6y agoio-ts does this. Although it's the other way around: you write the type guard (API is similar to writing a type) and it gives you the type for free.
- The_rationalist 6y agoTypescript has type erasure meaning that after compilation all information about types is lost. This means that you loose: * runtime type reflection * Reified generics