Releases: UselessPickles/ts-enum-util
Declaration Source Maps
Source maps are now generated and distributed for the TypeScript declaration files.
Reverting "fix" to source maps
Nothing was actually wrong with the source maps in 3.0.0. My "fix" in 3.0.1 actually broke it. I'm dumb. This release reverts back to 3.0.0.
Source Map Fix
The distributed source maps had incorrect paths to the source. this is now fixed.
Now Supporting TypeScript 2.9!
Source code and distributed type definitions are now compatible with TypeScript 2.9.
Unfortunately, in order to support TypeScript 2.9, I had to drop support for TypeScript versions prior to 2.8.
Use ts-enum-util
v2 if you require compatibility with older TypeScript versions.
Update TypeScript Compatibility Info
This is a minor documentation and NPM peer dependency updated.
TypeScript 2.9 introduced a breaking change to the keyof
operator that impacts this project. ts-enum-util
is currently only compatible with TyoeScript 2.3 - 2.8.
Stay tuned for version 3.0 of ts-enum-util
, which should be compatible with TypeScript 2.8+. Unfortunately, there's no way for me to specify the types of this project that is both compatible with TypeScript 2.9 and backwards compatible with versions earlier than 2.8.
Now More Immutable!
- Use
Object.freeze()
to make data immutable at run time. - Simplify some code because defensive copies are no longer necessary.
- Add several new unit tests and tslint tests to verify immutability (both compile-time and run-time).
Documentation and Peer Dependency Updates
No functional changes. Just behind-the-scenes testing updates that lead to updated documentation and peer dependency info.
- Added
dtslint
tests to verify compile-time types. - Verified compatibility with TypeScript 2.3+.
- Minor code style and code comments cleanup.
Improved Caching Performance
Improvements
- A
WeakMap
is now instead of aMap
to cacheEnumWrapper
instances. This ensures thatEnumWrapper
instances are garbage collected whenever their corresponding "enum-like" objects are garbage collected (no memory leaks). This should also improve cache set/get performance becauseWeakMap
implementations can feature O(1) constant time set/get. - The
$enum()
function was also optimized by making it a direct alias/reference toEnumWrapper.getCachedInstance()
.
Breaking Changes
Because WeakMap
solves the concern about memory leaks when ts-enum-util
is used on temporary enum-like objects, there's really no need to opt out of caching any more. Accordingly, the following API changes were made:
- Removed
EnumWrapper.createUncachedInstance()
- Removed optional
useCache
param to the$enum()
function (it now always uses the cache).
It's DONE! (for now)
- Optimization: Avoid double key lookups into a map for successful value->key reverse lookups.
- Additional code documentation about some of the optimizations.
- Added unit tests to ensure that key/value names matching Object.prototype properties do not cause false positives.
Optimizations
Some code optimizations:
- Several methods updated to use raw for() loops instead of Array.prototype.forEach and Array.prototype.map.
- Changed "isKey()" method to use Object.hasOwnProperty() on the original enum object instead of relying on a ES6 Set of keys.
- Use Array.prototype.slice to return defensive copies of lists of keys and values (instead of mapping from list of entries)
- Keys are now stored as a plain array instead of an ES6 Set.