-
Notifications
You must be signed in to change notification settings - Fork 2
fix: avoid parse errors in older umi builds #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,10 @@ import { getNumberPrecision, isE, isEmpty, num2str } from './numberUtil'; | |
| /** | ||
| * We can remove this when IE not support anymore | ||
| */ | ||
| export default class NumberDecimal implements DecimalClass { | ||
| origin: string = ''; | ||
| number: number; | ||
| empty: boolean; | ||
|
|
||
| class NumberDecimal implements DecimalClass { | ||
| constructor(value: ValueType) { | ||
| this.origin = ''; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure type safety and prevent potential runtime errors, it's best to initialize all class properties at the beginning of the constructor. The this.origin = '';
this.number = 0;
this.empty = false; |
||
|
|
||
| if (isEmpty(value)) { | ||
| this.empty = true; | ||
| return; | ||
|
|
@@ -90,7 +88,7 @@ export default class NumberDecimal implements DecimalClass { | |
| } | ||
|
|
||
| equals(target: DecimalClass) { | ||
| return this.toNumber() === target?.toNumber(); | ||
| return this.toNumber() === (target ? target.toNumber() : undefined); | ||
| } | ||
|
|
||
| lessEquals(target: DecimalClass) { | ||
|
|
@@ -117,3 +115,11 @@ export default class NumberDecimal implements DecimalClass { | |
| return num2str(this.number); | ||
| } | ||
| } | ||
|
|
||
| interface NumberDecimal { | ||
| origin: string; | ||
| number: number; | ||
| empty: boolean; | ||
| } | ||
|
|
||
| export default NumberDecimal; | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To ensure type safety and prevent potential runtime errors, it's best to initialize all class properties at the beginning of the constructor. The
BigIntDecimalinterface defines properties likenegative,integer, etc., as non-optional. However, if an emptyvalueis passed to the constructor, these properties are never initialized, leaving them asundefined, which violates the interface contract. Initializing them with default values makes the class more robust.