News for hackers. Stuff that matters.
Re:Announcing TypeScript 2.2 by aduffy on Wednesday February 22, 2017 @12:54PM (#13707477)
My favorite: the new `object` type. Non-nullable and cannot refer to primitives.
Re:Announcing TypeScript 2.2 by whatever_dude on Wednesday February 22, 2017 @01:08PM (#13707613)
The 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

Re:Announcing TypeScript 2.2 by dsp1234 on Wednesday February 22, 2017 @01:12PM (#13707653)
Non-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.

Re:Announcing TypeScript 2.2 by DanRosenwasser on Wednesday February 22, 2017 @01:28PM (#13707794)
Thanks 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. :)
Re:Announcing TypeScript 2.2 by benjaminjackman on Wednesday February 22, 2017 @01:21PM (#13707729)
I think you can use the `--strictNullChecks`[1] compiler option to get that behavior though.

1: https://www.typescriptlang.org/docs/handbook/compiler-option...

Re:Announcing TypeScript 2.2 by realharo on Wednesday February 22, 2017 @01:19PM (#13707701)
I 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).

Re:Announcing TypeScript 2.2 by whatever_dude on Wednesday February 22, 2017 @01:20PM (#13707720)
No, 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.

Re:Announcing TypeScript 2.2 by dsp1234 on Wednesday February 22, 2017 @01:42PM (#13707963)
since 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'.
Re:Announcing TypeScript 2.2 by whatever_dude on Wednesday February 22, 2017 @01:54PM (#13708095)
> 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.

Re:Announcing TypeScript 2.2 by dsp1234 on Wednesday February 22, 2017 @01:57PM (#13708137)
I did, sorry about that.
Re:Announcing TypeScript 2.2 by mohamedhegazy on Wednesday February 22, 2017 @01:26PM (#13707777)
Without `--strictNullChecks`, both `undefined` and `null` are in the domain of all types.
Re:Announcing TypeScript 2.2 by realharo on Wednesday February 22, 2017 @01:14PM (#13707660)
Can you show a few examples of where this is useful?
Re:Announcing TypeScript 2.2 by dsp1234 on Wednesday February 22, 2017 @01:49PM (#13708044)
You 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

Re:Announcing TypeScript 2.2 by realharo on Wednesday February 22, 2017 @02:12PM (#13708282)
Thanks. Sounds useful especially for library authors.