4 ms·
Question for TypeScript and specifically Angular 2: does Angular 2 being written in TypeScript mean that webapps based on Angular 2 that are also written in Typ
by stephen 10y ago
Question for TypeScript and specifically Angular 2: does Angular 2 being written in TypeScript mean that webapps based on Angular 2 that are also written in TypeScript, are basically 100% type-safe (e.g. all app-to-Angular library calls, or within-app view-to-model/etc. calls, are all type checked)?
I ask because after looking (admittedly very briefly) at writing an Ember app in TypeScript, it looked like because Ember assumes all of it's webapps will be JavaScript, there ends up being a lot of dynamic-/string-based idioms, e.g. model.set("property").
(There is a good SO post about turning this into a typed model.property.set(...) in TypeScript, but that solves just this one instance, and not the entire Ember experience.)
So, this left me with the feeling that for a TypeScript webapp to have a truly great/first-class/typed interaction with it's framework (Angular, Ember, whatever), that the framework itself would have to: a) be written in TypeScript, and b) have the founding assumption that most (all?) apps written for it would also be TypeScript.
So, per this post, Angular 2 is a), it's written in TypeScript. What about b)?
- lstamour 10y agob) is left as an exercise for the reader, to pick dependencies and protocols based on their merits, one consideration being support for types. But TypeScript does appear to be more than types alone, so there are other benefits. See also: AngularDart, which also has the same "b)" problem, but worse as it doesn't interact as easily with existing JS.
- ta_donk_gt 10y agoUsing TypeScript in Angular 2 is completely seamless, and I think most consider it the default, so 'b)' is likely close to what you describe. I don't think you could come close to approximating Angular 2's level of TypeScript integration with Ember. The one caveat is that templates have no type checking or refactoring support. This is fairly standard in html templates in any statically typed language framework, but it is still frustrating and unfortunate. You can safely rename a symbol in TypeScript files, and yet not be able to catch the references in templates without find and replace.
- continuational 10y agoReact with Flowtype gives you typed templates (or whatever you call the render() merhods).
- coltonv 10y agoNothing in Javascript can ever be completely type safe right now. For example, you compile your TS code and it compiles without error, but you pull a JSON object from the server and pass it into a function which is expecting the argument to implement a certain interface. The problem is the interface is dropped in compilation and there's no type checking at run-time, so there's no way for Typescript to know that the program will be type safe at run-time.
- k_bx 10y agoNot sure about TS, but a good type system would not mean you know the structure of dynamic JSON. It would just guarantee that before accessing some field, you would define in some way your code path what to do in case there is that field and in case there isn't. So, at the end, even if you missed the structure, you would have a clearly-defined error reporting logic (or whatever is necessary) at your runtime.
- tracker1 10y agoThat's one of my bigger niggles as well... You can use json schema for your schema checking though.
- tracker1 10y agoUsing Angular 2 without typescript, or a lot of features via babel + flow + (webpack|rollup|browserify). I couldn't imagine trying to write an ng2 app with ES5 alone... it would drive one insane. Not even just for type safety, but because of how decorators are used, it's much more verbose and mind-numbing. You can use TS for part of your app, once the environment is setup... iirc, there's a couple options for bringing in typings for existing libraries, and if you enjoy that, I'd say go for it. That said, I don't think it adds as much value as others seem to feel it brings.