Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(treewide): Enable strict null checking
Typescript defaults to treating null/undefined in a way that can leak them throughout code, and will also cause type issues (unexpected undefineds/anys) if you use them explicitly To avoid an unreviewable mess I have either widened types to allow null (where we own the type) or added non-null assertions (where we do not). This is preferable to not discerning nulls at all, and while it still creates a large (by LOC) change, it's hopefully not large (by variation of things) - and should transpile identically to JavaScript. There is one point where the code does not transpile identically to JavaScript. This is because it directly set something that we don't own which shouldn't be undefined to undefined. This is clearly incorrect, and I've replaced it with setting to an empty string instead. If it seems like this is bad practice, that's because it is. You shouldn't add non-null assertions all over the place because it makes typescript lie to you. It's of similar badness to adding `as x` everywhere. Unfortunately, worse practice would be mandating that typescript lie to you about nulls and undefineds everywhere, as our tsconfig has been doing. It's far better to limit the lie to these ~850 places where I've had to explicitly tell typescript "the world isn't actually like this - that's OK, carry on anyway". If you're worried about blames from this change - first: I believe it's worth it, second: this change should only affect single lines, so using --ignore-rev should work very well on it In the future, probably we should remove some of these assertions, although some changes we'll have to make to remove them are likely either tedious or dangerous. Signed-off-by: Skyler Grey <[email protected]> Change-Id: I1770a1a8be3f45b45bda0fd2bcd57563add25924
- Loading branch information