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...
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.
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.
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.
This is incorrect, as is the announcement. The following is valid.
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.