5 ms·
> The most common JavaScript error I encounter is accessing fields of undefined objects. TypeScript has optional null checking if you want it. Given that it su
by seanmcdirmid 9y ago
> The most common JavaScript error I encounter is accessing fields of undefined objects.
TypeScript has optional null checking if you want it. Given that it supports union types, null/undefined tracking fit nicely into the language.
- k__ 9y agoCan I type stuff as any but still non nullable?
- seanmcdirmid 9y agoI think any in TypeScript's context means "not in the type system", and all type rules bounce off it. So if k's type is any, and you type k.foo, it doesn't bother checking it. I assume the same applies to any null checking.
- k__ 9y agoThe "object" type is probably what I was searching.
- spiralx 9y agoThe object type is the type of all non-primitive types, what you want is the Object type instead. Yes, it's confusing, especially as there's also the {} type! This article goes over the differences: https://blog.mariusschulz.com/2017/02/24/typescript-2-2-the-object-type https://blog.mariusschulz.com/2017/02/24/typescript-2-2-the-...