4 ms·
I wish TypeScript checked types at runtime.... boo... The only language that I've seen in JS land that is trying to get this right is AtScript from the Angular
by programminggeek 12y ago
I wish TypeScript checked types at runtime.... boo...
The only language that I've seen in JS land that is trying to get this right is AtScript from the Angular team.
https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit97HnZoKVygDxpWzEYW0U/mobilebasic?viewopt=127 https://docs.google.com/document/d/11YUzC-1d0V1-Q3V0fQ7KSit9...
Looks interesting so far.
- timothya 12y agoDart can as well. In fact, I think that the whole type spec in AtScript is based on Dart. Edit: Quote from the doc you linked: "This runtime type system is modeled after Dart’s runtime type assertion. Dart users working on large scale applications point out that optional types and runtime type assertions work well in practice."
- pspeter3 12y agoWhy do you want TypeScript to check types at run time? Integration with other JavaScript code?
- mjibson 12y agoValidation of JSON responses is the big win.
- programminggeek 12y agoI am a big fan of design by contract. (http://retromocha.com/obvious/ http://retromocha.com/obvious/) I don't trust user input in any form, including the database. So, while a system like TypeScript that checks types in the code is fantastic, it doesn't check types in the input, which is how a lot of problems happen in the first place. Seriously, just import one legacy dataset into your system or have to work with some JSON api, and all of a sudden you can't trust that the data is valid, correctly typed, or even sane. Doing proper validation of types and data integrity at any input point can save you a whole category of sadly common bugs. That includes data coming out of any data source you use, like a database. Runtime type checking is another tool to make validated data a common, sane thing.
- riffraff 12y agowhy do you want that? The rationale given in the AtScript presentation seemed pretty weak to me.
- programminggeek 12y agoType checking at runtime allows for runtime data contracts. There are a lot of benefits to that, largely in being able to enforce stronger boundaries in your code. Strong boundaries allow for potentially better code reuse, fewer bugs, and a more confident style. Once you setup a type or validation boundary, you know that you no longer need to check for type errors and so forth elsewhere in the code, if only for the fact that the code will blow up before it even gets there. That means you write less code, have fewer bugs, and can spend more time doing important things, like playing Quake 2.
- klibertp 12y agoYou can have type checking - or even much stronger validation - on runtime with contracts. Racket and TypedRacked are an example of how well contracts and static typing can work together, providing both compile-time and runtime guarantees. I'm sure something like this will come to "idustrial grade" languages in a decade or so...
- doublerebel 12y agoContracts.js [1] has been actively developed for quite a while. It uses Sweet.js "macros" to provide runtime type-checking. Also usable in CoffeeScript. It doesn't get much hype because it's not new, but that's why I like it. Reliable and stable. [1] http://disnetdev.com/contracts.js/ http://disnetdev.com/contracts.js/ [EDIT: Contracts.js is based off Racket, advantages pointed out by another commenter.]