- TypeScript and Elm have different goals
- Soundness is not a goal of the TypeScript type system
- TypeScript Design Goals (and non-goals)
- TypeScript's any type
- Nominal vs structural typing
TypeScript's any vs. Elm's Debug.todo
TypeScript's any essentially "turns off" type checking in areas that any passes through.
In Elm:
- You can get a type that could be anything with Debug.todo, but you can't build your app with --optimize if it has Debug.todo's in it
- You will still get contradictions between inconsistent uses of a type that could be anything (see this Ellie example)
This Ellie example (with compiler error as expected) and this TypeScript playground example (with no error) show the difference.
- any can not be used in places that take never
- any vs unknown
- JSON.parse returns any, as do many core and published typings
- io-ts lets you validate JSON similar to JSON decoders in Elm
- Definitely Typed (published type definitions for NPM packages)
- Definitely Typed search
- noImplicitAny
- TypeScript `strict mode in tsconfig
- Dillon's post TypeScript's Blind Spots
- JS semantics allow types that may not be intended (like adding a string + object, '' + {} === '[object Object]')
- Function parameters are inferred to be any regardless of implementation if they aren't given an explicit type
- Type narrowing
- TypeScript has untagged unions (just called Unions) - in Elm, there are only tagged unions (called Custom Types)
- Undefined vs null
- TypeScript's Void type
- TypeScript doesn't have checked exceptions like Java (there is a discussion about this on GitHub) - Elm only has explicit errors as data that must be handled exhaustively like other data types
- Discriminated unions vs Elm custom types
- Literal types
- TypeScript allows number literal values, but arithemtic expressions return generic number values instead of literal types
- Enums
- Branded types in TypeScript vs opaque types
- Elm Radio Opaque Types episode
- Switch statements are not exhaustive - you can add an eslint rule to check that (or the never trick, assert unreachable)
- Key of operator in TypeScript
- TypeScript's type system can do some cool things that Elm can't (for better and for worse)
- Prisma
- Prisma advanced TS meetup talks
- Tuples in TypeScript are just arrays and use narrowing - Tuple in Elm is a specific type
- elm-ts-interop
- TypeScript handbook on official site