ts-enum-util
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -15,4 +15,3 @@ "use strict"; | ||
else if (visitor[symbols_1.handleUnexpected]) { | ||
return processEntry(visitor[symbols_1.handleUnexpected], this | ||
.value); | ||
return processEntry(visitor[symbols_1.handleUnexpected], this.value); | ||
} | ||
@@ -19,0 +18,0 @@ else { |
@@ -23,9 +23,2 @@ "use strict"; | ||
} | ||
Object.defineProperty(EnumWrapper.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return "EnumWrapper"; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
EnumWrapper.prototype.toString = function () { | ||
@@ -35,4 +28,4 @@ return "[object EnumWrapper]"; | ||
EnumWrapper.prototype.keys = function () { | ||
var _a; | ||
var _this = this; | ||
var _a; | ||
var index = 0; | ||
@@ -56,4 +49,4 @@ return _a = { | ||
EnumWrapper.prototype.values = function () { | ||
var _a; | ||
var _this = this; | ||
var _a; | ||
var index = 0; | ||
@@ -77,4 +70,4 @@ return _a = { | ||
EnumWrapper.prototype.entries = function () { | ||
var _a; | ||
var _this = this; | ||
var _a; | ||
var index = 0; | ||
@@ -203,2 +196,3 @@ return _a = { | ||
exports.EnumWrapper = EnumWrapper; | ||
EnumWrapper.prototype[Symbol.toStringTag] = "EnumWrapper"; | ||
//# sourceMappingURL=EnumWrapper.js.map |
@@ -13,4 +13,3 @@ import { handleUnexpected, handleNull, handleUndefined, unhandledEntry } from "./symbols"; | ||
else if (visitor[handleUnexpected]) { | ||
return processEntry(visitor[handleUnexpected], this | ||
.value); | ||
return processEntry(visitor[handleUnexpected], this.value); | ||
} | ||
@@ -17,0 +16,0 @@ else { |
@@ -21,9 +21,2 @@ import { isNonNumericKey, getOwnEnumerableNonNumericKeys } from "./objectKeysUtil"; | ||
} | ||
Object.defineProperty(EnumWrapper.prototype, Symbol.toStringTag, { | ||
get: function () { | ||
return "EnumWrapper"; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
EnumWrapper.prototype.toString = function () { | ||
@@ -33,4 +26,4 @@ return "[object EnumWrapper]"; | ||
EnumWrapper.prototype.keys = function () { | ||
var _a; | ||
var _this = this; | ||
var _a; | ||
var index = 0; | ||
@@ -54,4 +47,4 @@ return _a = { | ||
EnumWrapper.prototype.values = function () { | ||
var _a; | ||
var _this = this; | ||
var _a; | ||
var index = 0; | ||
@@ -75,4 +68,4 @@ return _a = { | ||
EnumWrapper.prototype.entries = function () { | ||
var _a; | ||
var _this = this; | ||
var _a; | ||
var index = 0; | ||
@@ -201,2 +194,3 @@ return _a = { | ||
export { EnumWrapper }; | ||
EnumWrapper.prototype[Symbol.toStringTag] = "EnumWrapper"; | ||
//# sourceMappingURL=EnumWrapper.js.map |
@@ -54,3 +54,2 @@ import { StringKeyOf } from "./types"; | ||
constructor(enumObj: T); | ||
readonly [Symbol.toStringTag]: string; | ||
/** | ||
@@ -114,3 +113,3 @@ * @return "[object EnumWrapper]" | ||
*/ | ||
getKeys(): (StringKeyOf<T>)[]; | ||
getKeys(): StringKeyOf<T>[]; | ||
/** | ||
@@ -117,0 +116,0 @@ * Get a list of this enum's values. |
{ | ||
"name": "ts-enum-util", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "TypeScript Enum Utilities", | ||
@@ -37,3 +37,3 @@ "repository": { | ||
"jest:coverage": "npm run clean:coverage && jest --coverage", | ||
"dtslint:v2_9_plus": "dtslint type_tests/v2_9_plus", | ||
"dtslint:v2_9_plus": "dtslint --expectOnly type_tests/v2_9_plus", | ||
"dtslint": "run-s clean:dist build:types dtslint:v2_9_plus", | ||
@@ -51,18 +51,14 @@ "test": "run-s compile prettier:test lint dtslint jest", | ||
"devDependencies": { | ||
"@types/jest": "24.0.9", | ||
"@types/node": "10.12.18", | ||
"coveralls": "3.0.3", | ||
"dtslint": "0.5.3", | ||
"jest": "24.1.0", | ||
"@types/jest": "24.0.23", | ||
"coveralls": "3.0.9", | ||
"dtslint": "2.0.2", | ||
"jest": "24.9.0", | ||
"npm-run-all": "4.1.5", | ||
"prettier": "1.16.4", | ||
"rimraf": "2.6.3", | ||
"ts-jest": "24.0.0", | ||
"tslint": "5.13.1", | ||
"prettier": "1.19.1", | ||
"rimraf": "3.0.0", | ||
"ts-jest": "24.2.0", | ||
"tslint": "5.20.1", | ||
"tslint-config-prettier": "1.18.0", | ||
"typescript": "3.3.3333" | ||
"typescript": "3.7.2" | ||
}, | ||
"peerDependencies": { | ||
"typescript": ">= 2.9.1" | ||
}, | ||
"keywords": [ | ||
@@ -69,0 +65,0 @@ "typescript", |
@@ -16,3 +16,3 @@ import { | ||
export type EnumValueMapperCore<E extends string | number, T> = { | ||
[P in E]: T | typeof unhandledEntry | ||
[P in E]: T | typeof unhandledEntry; | ||
}; | ||
@@ -19,0 +19,0 @@ |
@@ -45,4 +45,6 @@ import { | ||
} else if (visitor[handleUnexpected]) { | ||
return processEntry(visitor[handleUnexpected]!, (this | ||
.value as any) as WidenEnumType<E>); | ||
return processEntry( | ||
visitor[handleUnexpected]!, | ||
(this.value as any) as WidenEnumType<E> | ||
); | ||
} else { | ||
@@ -49,0 +51,0 @@ throw new Error(`Unexpected value: ${this.value}`); |
@@ -35,3 +35,3 @@ import { | ||
export type EnumValueVisitorCore<E extends string | number, R> = { | ||
[P in E]: EnumValueVisitorHandler<P, R> | typeof unhandledEntry | ||
[P in E]: EnumValueVisitorHandler<P, R> | typeof unhandledEntry; | ||
}; | ||
@@ -38,0 +38,0 @@ |
@@ -96,6 +96,2 @@ import { StringKeyOf } from "./types"; | ||
public get [Symbol.toStringTag](): string { | ||
return "EnumWrapper"; | ||
} | ||
/** | ||
@@ -264,3 +260,3 @@ * @return "[object EnumWrapper]" | ||
*/ | ||
public getKeys(): (StringKeyOf<T>)[] { | ||
public getKeys(): StringKeyOf<T>[] { | ||
// need to return a copy of this.keysList so it can be returned as Array instead of ReadonlyArray. | ||
@@ -690,2 +686,28 @@ return this.keysList.slice(); | ||
// HACK: Forcefully overriding the value of the [Symbol.toStringTag] property. | ||
// This was originally implemented in the class as recommended by MDN | ||
// Symbol.toStringTag documentation: | ||
// public get [Symbol.toStringTag](): string { return "EnumWrapper"; } | ||
// | ||
// However, after upgrading to TypeScript 3.7, this caused compiler errors | ||
// when running dtslint due to the getter being emitted to the .d.ts file, | ||
// but TSC complaining that getters aren't allowed in "ambient" contexts. | ||
// This seems to be realated to a known breaking change: | ||
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#class-field-mitigations | ||
// | ||
// To avoid requiring TypeScript 3.6+ to use ts-enum-util, I no longer | ||
// implement the getter on the class and instead simply set the value of | ||
// the [Symbol.toStringTag] property on the class prototype to the desired | ||
// string. | ||
// | ||
// I also tried implementing it as: | ||
// public readonly [Symbol.toStringTag] = "EnumWrapper"; | ||
// But this got emitted to the .d.ts file with the initializer, | ||
// causing a compiler time error about initializers not allowed in an | ||
// "ambient" context. So I had to omit the declaration of the | ||
// [Symbol.toStringTag] in the class declaration and hackishly set its | ||
// value here (not important to have it part of the class declaration | ||
// as long as the value exists at runtime). | ||
(EnumWrapper.prototype as any)[Symbol.toStringTag] = "EnumWrapper"; | ||
export namespace EnumWrapper { | ||
@@ -692,0 +714,0 @@ /** |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
211772
0
11
3685