3 ms·
> javascript is just typescript with documentation stripped off. JS, at its core is a dynamically typed, functional language. Typescript aims to model a stron
by orange8 7y ago
> javascript is just typescript with documentation stripped off.
JS, at its core is a dynamically typed, functional language. Typescript aims to model a strongly typed, OPP language. The two programming paradigms have their own strengths, weaknesses and most importantly: patterns and best practices.
If the only difference between your pure javascript code and your typescript code is the annotations, you are doing it wrong.
- Udik 7y ago> Typescript aim to model a strongly typed, OPP language. Do you think? I just take TS for what it gives me, documentation and static code analysis. I can write down my knowledge and expectations about the code and have the tool keep track of it for me, removing the cognitive load of doing it myself- which I'd have to otherwise. Can you give me an example of a pattern that is "good" in JS and not in TS, or the other way round? I'm curious.
- orange8 7y agoA good indirect example is an actual feature added to JS recently, which are classes. Classes are the main unit of OOP, while functions are the main unit in the functional paradigm. The class syntax in JS is not a real new structure added to the language, but just syntax sugar. Underneath it all, the JS compiler just converts it to a regular JS function using a specific pattern. You could, if you wanted, save the compiler that work by just coding using that pattern to begin with. When using TS the class syntax fits in perfectly for me, an in pure JS I'd stick to functions.
- Udik 7y agoSo you're giving a javascript feature as an example of a pattern that doesn't fit javascript. Then you claim to use an equivalent but syntactically different form in js? How does this constitute a different pattern?
- iaml 7y ago> Typescript aims to model a strongly typed, OPP language That's a rather puzzling statement, to be honest. Strong type system is explicitly one of the non-goals[0]. I write typescript code everyday and most of it is functional. Things like fp-ts[1] make it even more enjoyable. [0] https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals https://github.com/Microsoft/TypeScript/wiki/TypeScript-Desi... [1] https://github.com/gcanti/fp-ts https://github.com/gcanti/fp-ts
- orange8 7y agoAm comfortable using both OOP and functional styles, though I do enjoy the flexibility and terseness that can be produced from the functional approach. What I meant by the comment is that when using TS, I just find it more easy and natural to go with the proper OOP approach. I think the very existence of a separate library to enable a more functional style in TS proves this goal has not been met yet.
- iaml 7y agoFunctional languages usually have extensive standard library, while js does not. Adding it is not really a goal of ts.
- samhh 7y agoIt's not very strongly typed at all, and it absolutely doesn't force you into the OOP paradigm. Why don't I consider it strongly typed?: Structurally subtyped as opposed to nominal typing, the pervasiveness of any, allowance for vanilla JS coercion, exceptions and promise rejections are untyped, etc.
- orange8 7y agoI agree, that's why I said TS aims to model a strongly typed languange.