13 ms·
Announcing TypeScript 2.2
- aduffy 10y agoMy favorite: the new `object` type. Non-nullable and cannot refer to primitives.
- whatever_dude 10y agoThe new `react-native` jsx target is also a good step in the right direction of creating smooth React Native projects in TS. I can't wait for it to be a seamless dev experience, but now the ball's in RN's court. [1] (Context: using TS in a RN project is currently a bit disjointed because of its closed dev bundling workflow. You need a separate build task running concurrently to feed JS files to the main watch/build task.) [1] https://github.com/facebook/react-native/pull/11932 https://github.com/facebook/react-native/pull/11932
- dsp1234 10y agoNon-nullable This is incorrect, as is the announcement. The following is valid. class Bar{} let foo:object = new Bar() foo = null foo = undefined edit: For the people mentioning, --strictNullChecks. That applies to all types not just object. For example, "let x:string = null" would also be an error. That option applies to any type that is not of type Any/null/undefined, and has been in place since 2.0. In that way, "object" is non-nullable under strictNullChecks just as every other type is.
- realharo 10y agoI guess it's only so with `strictNullChecks` enabled? Anyway, TypeScript's `strictNullChecks` in general has a huge hole in that it allows uninitialized properties (https://github.com/Microsoft/TypeScript/issues/8476 https://github.com/Microsoft/TypeScript/issues/8476).
- whatever_dude 10y agoNo, object is not a nullable type. For your code to work, you'd need to run it with strictNullChecks disabled. That's probably what you're doing, since it's the default.
- mohamedhegazy 10y agoWithout `--strictNullChecks`, both `undefined` and `null` are in the domain of all types.
- dsp1234 10y agosince it's the default. It's not the default for the command line compiler. Also, all types (except Any/null/undefined) are non-nullable under that option, so that's not what makes object special (it's the no primitive types that is important). >tsc test.ts >tsc test.ts --strictNullChecks > test.ts(3,1): error TS2322: Type 'null' is not assignable to type 'object'.
- whatever_dude 10y ago> you'd need to run it with strictNullChecks disabled. That's probably what you're doing, since it's the default I think you misinterpreted my reply. I meant the default is off. That's what your code shows.
- dsp1234 10y agoI did, sorry about that.
- benjaminjackman 10y agoI think you can use the `--strictNullChecks`[1] compiler option to get that behavior though. 1: https://www.typescriptlang.org/docs/handbook/compiler-options.html https://www.typescriptlang.org/docs/handbook/compiler-option...
- DanRosenwasser 10y agoThanks for catching - I've updated the blog post. I tend to just use `strictNullChecks` by default, as it's typically the best option for any new code. :)
- realharo 10y agoCan you show a few examples of where this is useful?
- dsp1234 10y agoYou can read the proposal and discussion around the feature on the github suggestion page for this feature. The initial suggestion was made because there are certain functions in JavaScript that expect a non-primitive type in order to function. Such as Object.create, Object.getPrototypeOf, etc. Previous to this there was no way to model the functions with type safety, such that a developer would be prevented from accidentally sending a primitive value into those functions. This is because Typescript doesn't have the ability to say "Any type except X, Y and Z". So a new type was needed for this. https://github.com/Microsoft/TypeScript/issues/1809 https://github.com/Microsoft/TypeScript/issues/1809
- realharo 10y agoThanks. Sounds useful especially for library authors.
- bcherny 10y agoObject type, better index access, and the quick fixes are all great additions. Awesome job TS team, keep it coming!
- ihsw 10y agoRelaxing index-signature access is definitely great as it will make writing code easier. Dynamic properties can lead you to hairy code but it's hard to ignore the reality that it's used everywhere. For example, no more awkward `e["code"]` where `e.code` is just as valid.
- ng12 10y agoSpeaking of tooling -- has anyone had a good experience with Typescript in IntelliJ/Webstorm? It does a fantastic job figuring out ES6 code but seems to totally choke on Typescript. I'd like to avoid switching to Visual Studio.
- lukaszjb 10y agoMy proposition is out of the box but maybe get a chance to VSCode?
- pmoleri 10y agoIn my team we used to be splitted between sublime/webstorm/atom, now we all are pretty happy with VS Code for typescript and javascript.
- ng12 10y agoMoving a team of ~20 engineers from IJ to VSCode for a single technology is a nonstarter. IJ is still the preferred IDE for the backend and works perfect for everything we've used that's not Typescript.
- Derander 10y agoThat's odd. I work in a 100% typescript shop and about half the devs use intellij and webstorm full time without much trouble. Jump to definition/auto import/implement interface/etc all work.
- ken47 10y agoI'll second that. I use an IDE from the Intellij family and things work fine.
- jameslk 10y agoMake sure you turn on the native TypeScript Language Service feature, otherwise you'll be getting your IDE's parser, which is always behind the standard and doesn't work very well: > Select the Use TypeScript Service check box to get native support from the TypeScript Language Service according to the up-to-date specifications. In this case syntax and error highlighting is performed based on the annotations retrieved from the TypeScript Language Service while code completion lists contain both suggestions from the TypeScript Language Service and suggestions calculated by IntelliJ IDEA itself. https://www.jetbrains.com/help/idea/2016.2/typescript-support.html#d829002e95 https://www.jetbrains.com/help/idea/2016.2/typescript-suppor...
- codr4life 10y agoCrumbles from the design-table. Oh look, a new object type. I'm not even sure this is an improvement to straight JS any more, it just fails in more exotic ways from pretending to be something it isn't. Once the choice is made to compile to JS, there are plenty of real languages to choose from.
- Nemcue 10y agoI don't think you're familiar with what TypeScript is trying to achieve. It's not supposed to be another language entirely, but a standards-compatible type-safe version.
- deleted 10y ago[deleted]
- treehau5 10y agoI know this probably comes up each typescript thread, but I still cannot figure out why I should use TS instead of flow + es6, and maintaining the typing definitions always discourages me as it's one more thing that needs to be kept up to date. Am I working on old information here?
- Nemcue 10y agoWhy would flow + es6 be better?
- MehdiHK 10y agoAvoid vendor locking. Someday in near future if you don't like flow anymore, you can just strip all type annotations with Babel and move on. You are not risking ending up like coffeescript.
- treehau5 10y agoAlso, you can progressively opt in to add typing information, while still getting most of the benefits without.
- whatever_dude 10y agoThe same can be done with TypeScript. Type inference has been added to it in 2015.
- treehau5 10y agoAwesome, did not know this.
- shados 10y agoTypeScript type inference is minimal though and doesn't go very far. It falls back to "any" very quickly (and if you use the noImplicitAny option, then you have to type almost everything). It does a decent enough job at return types, but not a whole lot beyond that.
- pixie_ 10y agoWoo :) whenever I have to work with an old javascript code base now I always add typings to it first. It makes it orders or magnitude easier to work with and refactor after that.
- Fifer82 10y agoI love you Microsoft!
- dandare 10y agoI have to admit I am getting lost in all these new language constructs :(. I worry that soon I will not be able to read TS code of more experienced programmers. That being said, the only way forward is to learn! But there seems to be total lack of solid learning resources with plentiful of examples and most importantly "best practices" that explain why the new construct is better and when to use it over the old way.