5 ms·
The 2 big things missing on typescript: 1) Operator overloading 2) Runtime type checking of JSON payloads (on dev env at least) Can't believe in 2019 every l
by mattigames 7y ago
The 2 big things missing on typescript:
1) Operator overloading
2) Runtime type checking of JSON payloads (on dev env at least)
Can't believe in 2019 every library has to create its own way to add 2 elements of the same class together e.g dataframe1.addTo(dataframe2) vs dataframe1 + dataframe2
And the most common error that it should help catch during development is that you get a JSON and you cast it but it means nothing cause on runtime the JSON can be something completely different and nothing breaks until is somewhere else hard to debug, I get that Microsoft don't want to add runtime overhead but it should be possible at least on development mode.
- farnsworth 7y ago> 1) Operator overloading Please, please, please, no.
- mattigames 7y agoYou know it would be completely transparent right? Just gets transpiled into .__add__(obj)
- jakelazaroff 7y agoThe explicit goal of TypeScript is to be JavaScript, with types — i.e. not introduce any features not likely to land in an ECMAScript spec.
- mattigames 7y agoWhich is a shame because JavaScript is constrained due needing backwards-compatibility above all (among other issues) but TypeScript isn't
- MaulingMonkey 7y agoNot much of a shame IMO - there are plenty of other languages that transpile to JS without those goals, if you don't care about backwards compatability and 1:1 mappings to vanilla JS. On the other hand, there's only one language that I'm aware of - TypeScript - prioritizing these things, which is a major selling point of it to me. I don't want yet another leaky abstraction, or yet another runtime heavy enough for those abstractions to not leak. I just want enough types for my intellisense to work right, and for my sorry ass - spoiled by years of nothing but static typing systems - to be able to code without drowning in a veritable sea of uncaught type errors to debug, when I poke frontend stuff.
- ujoh1 7y agoHello See also how you can start making steady daily passive incomes on virta stock trading without you risking your money and your investment visit the website here http://www.virtatrade.com/index.php http://www.virtatrade.com/index.php for more details
- mattigames 7y agoTyped and those features? there isn't a single one. But yeah, maybe what I need is a fork of TypeScript with those features (or maybe some sort of plugin)
- watt 7y agoWe already saw this play out in Scala. People end up abusing these to create absolutely unreadable "DSL"s. Even when it's tastefully done, for example the "!" and "?" operator for messages in Akka, it's not better than the names "tell" and "ask".
- mattigames 7y agoFair enough.
- hermanradtke 7y agoI use https://github.com/gcanti/io-ts https://github.com/gcanti/io-ts for the runtime checking. It is similar to tcomb (same author)! You can even define the type via io-ts and then make a TypeScript interface out of it! Given this, and the other libraries that do something similar, I am not sure why Microsoft needs to add it to the language.
- nsonha 7y ago1) If your motivation is heavy mathematical programming then I hear you, but beware that you are the minority of the language's userbase, (more generally, most application-level programming languages' userbase), it's not something most people care about. If you want to write clever DSLs and/or name methods in ways that save keystrokes like in scala, NO, please. 2) There are libraries such as runtypes and io-ts that integrate well with the static type system
- MaulingMonkey 7y agoRE: JSON: I've started tagging my JSON blobs as `unknown` and then using type guards (typeof, instanceof, field access existence checks, Array.isArray checks, user defined type guards[1], etc.) my way to inferring the shape of that JSON blob is as expected, and it seems to work pretty well. [1] https://www.typescriptlang.org/docs/handbook/advanced-types.html#user-defined-type-guards https://www.typescriptlang.org/docs/handbook/advanced-types....
- rkuykendall-com 7y ago> Runtime type checking of JSON payloads We've been using Mobx State Tree for this, which also gives us frontend models and automatically generates interfaces. Obviously only works for you if you're using Mobx, but we love it. https://github.com/mobxjs/mobx-state-tree https://github.com/mobxjs/mobx-state-tree