I understand that this may be a classic javascript issue, but I have too often found that I am using:
if (!something) {
to verify that something not undefined or null in TypeScript.
This is very error prone! When used in number "0" will match, and when used in enum first element will match too (by default, the first element is set to "0")!
Is there any way to handle this in TypeScript? Is there a way to configure TypeScript to forbid an exclamation mark before anything other than boolean (and any )? Will this configuration make sense or am I missing something trivial?
Must:
if (something === null || something === undefined) {
instead, to verify that something is defined or not? And is there a way to ensure this in a team?
javascript typescript tslint
electrotype
source share