Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If anyone wants to see for themselves what life is without null, TypeScript has an option to type-check for possible null/undefined values with strictNullChecks[0]. It's a game changer. The con: you have to check every variable that could be null/undefined before using it. The pro: you have to check every variable that could be null/undefined before using it :)

[0] https://basarat.gitbooks.io/typescript/docs/options/strictNu...



Our stack is Typescript and Kotlin, and I find handling of null simple and safe, especially in Kotlin there is decent supporting functionality https://kotlinlang.org/docs/reference/null-safety.html

With Java we used @NotNull annotations and IDE support to give warnings. Luckily we are converting our legacy code base to Kotlin.

With conditional type conditions Typescript will have better support than earlier:

    type NonNullable<T> = Diff<T, null | undefined>;  // Remove null and undefined from T
Source and the examples in: https://github.com/Microsoft/TypeScript/pull/21316


Just a followup point: for new TypeScript projects, strongly consider using the “strict” compiler flag. This flag enables strict null checks along with a number of other useful checks / restrictions, such as disallowing variables without known types from being treated as “any”. These checks will catch bugs and improve your code but trying to enable them after the fact can be painful




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: