5 ms·
Can you elaborate on the changes in TS that hint at dependent types? That's interesting.
by amw-zero 5y ago
Can you elaborate on the changes in TS that hint at dependent types? That's interesting.
- namelosw 5y agoI'm not referring to some specific changes. It's just there are many type operators already and still not enough to express JavaScript. In the earlier versions of TypeScript, I often stuck with something natural in JavaScript but cannot express the same thing with type annotations - It's like opening a pandora box, once some advanced type operators have been introduced, whenever I played with them I would quickly found more type operators to be desired. And so it did. Things were getting better over years, there were a lot more type operators, mapped types, the infer keyword, etc. I feel it points to a direction: There is still a lot of existing JavaScript functions' type depend on the input which cannot be well-typed. For example, there are functions similar printf in most languages, or return type T when 0 is passed otherwise return type U. To satisfy those cases, we'll basically reinvent a whole new programming language in the type system - if the new language happens to be JavaScript itself it would be similar to other dependent type systems.
- aabbcc1241 5y agoSomeone claimed the type system of typescript is turning complete. This example shows how to derive types from string based sql statement: https://github.com/codemix/ts-sql https://github.com/codemix/ts-sql
- RobertKerans 5y ago[edit, not quite what GP was referring to, but] At the minute, via [depending on context] a combination of generics/conditional types, unions/literals, type constructors, and [more recently] string templating you can get close in certain circumstances. It tends to be very fiddly though, and [IME] it's quite easy to cause TS to stop narrowing types properly. Someone else with more experience may be able to weight in -- despite using it for a few years I'd not really bothered to exercise some of the more expressive parts of the system until string templating experiments started popping up last year. This issue thread on the TS repo may be of interest: https://github.com/microsoft/TypeScript/issues/33014 https://github.com/microsoft/TypeScript/issues/33014