Skip to content

Commit

Permalink
Remove null assertions (#39)
Browse files Browse the repository at this point in the history
* Remove null assertions

* Fix lint
  • Loading branch information
jscheiny authored Jun 29, 2018
1 parent 39b665c commit d96f169
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/measure/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export function multiplyUnits<L extends Unit, R extends Unit>(left: L, right: R)
continue;
}
const [, exponent] = symbolAndExponent;
if (dimension in result) {
const newExponent = result[dimension]![1] + exponent;
const resultValue: SymbolAndExponent | undefined = result[dimension];
if (resultValue !== undefined) {
const newExponent = resultValue[1] + exponent;
if (isExponent(newExponent)) {
result[dimension]![1] = newExponent;
resultValue[1] = newExponent;
} else {
throw new Error(ArithmeticError);
}
Expand All @@ -40,7 +41,8 @@ export function multiplyUnits<L extends Unit, R extends Unit>(left: L, right: R)
}
}
for (const dimension in result) {
if (result[dimension]![1] === 0) {
const value = result[dimension];
if (value !== undefined && value[1] === 0) {
delete result[dimension];
}
}
Expand Down

0 comments on commit d96f169

Please sign in to comment.