[enhance] Small bundle reduction by using typescript 'declare' #177
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
TypeScript 3.7 introduced a new 'declare' property modifier, which enables declaring property types without setting the default to void 0 in javascript. This is useful when they are actually set in the constructor. The end result is several lines removed from output that don't need to be executed.
Solution
We also start using optional chaining in tests. We need the latest prettier to work with this new syntax.
Optional chaining is not used in the main code as it results in extra output bloat.
Before
src/index.ts → dist/index.umd.min.js...
┌────────────────────────────────────────┐
│ │
│ Destination: dist/index.umd.min.js │
│ Bundle Size: 21.53 KB │
│ Minified Size: 21.43 KB │
│ Gzipped Size: 6.86 KB │
│ │
└────────────────────────────────────────┘
After
src/index.ts → dist/index.umd.min.js...
┌────────────────────────────────────────┐
│ │
│ Destination: dist/index.umd.min.js │
│ Bundle Size: 21 KB │
│ Minified Size: 20.9 KB │
│ Gzipped Size: 6.76 KB │
│ │
└────────────────────────────────────────┘