5 ms·
> Your compiler giving you a type check error is saying that the program is meaningless. The TypeScript compiler will absolutely give you errors for well-forme
by cxr 4y ago
> Your compiler giving you a type check error is saying that the program is meaningless.
The TypeScript compiler will absolutely give you errors for well-formed programs that are guaranteed* do the right thing with respect to what the author intended and that anyone else can see is correct but that the TypeScript compiler itself doesn't reason about correctly. In instances where this happens, it's very useful to be able to ignore them—just like you might ignore the protests of a misinformed team member who insists that such-and-such won't work, even though it provably will. (Although the alternative of just not using the TypeScript compiler can be a worthwhile decision as well.)
* not to be confused with undefined behavior in C where it might just happen to work with one known compiler/platform combo but break horribly for other valid targets
- munificent 4y agoThe cost for this is that programs with type errors must still be specified to have a well-defined semantics. That in turn means that you can't hang useful language features off static types. For example, TypeScript explicitly declares as a design goal that they don't use the type system to generate different code: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals https://github.com/Microsoft/TypeScript/wiki/TypeScript-Desi... Meanwhile in Dart, you can write: double d = 1; In Dart, doubles and integers are different types with different representations. The above line of code works because if we see an integer literal in a context where a floating-point number is expected, we implicitly treat it as a double literal. Note that there's no runtime conversion here. We can do this because Dart does have a sound type system and is happy to use it for language features. That's also why Dart (and other statically typed languages) support extension methods while TypeScript does not: https://github.com/microsoft/TypeScript/issues/9#issuecomment-74302592 https://github.com/microsoft/TypeScript/issues/9#issuecommen... If the language gives users the ability to type their code, it's really nice to be able to give them as much value in return for their effort. That means building language features on top of them and using types to generate smaller, faster code. But languages with unsound type systems or that treat programs with type errors as well formed can't really do that.