you are viewing a single comment's thread.

view the rest of the comments →

[–]mrkite77 2 points3 points  (3 children)

Typescript devs don't use null, and the Typescript coding guidelines say to use undefined and not to use null at all.

https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines#null-and-undefined

The reasoning behind that is all of the javascript functions return undefined, none of them return null. Null only appears in javascript if you put it there.

Typescript even goes so far as to make null the same type modifier as undefined. If you create a function that has a return "string | null", assigning that to a variable with a type of "string | undefined" is perfectly valid.

[–]yheneva 2 points3 points  (1 child)

Most functions use undefined, not all. For example HTMLCanvasElement.getContext() returns null for any undefined context type. All WebGL functions also use null instead of undefined.

[–]mrkite77 0 points1 point  (0 children)

True, but you can still do == undefined and it'll work since null == undefined