From 997db3620b6cff8730d56225d399ad9f3977442e Mon Sep 17 00:00:00 2001 From: Mazlan Date: Sat, 14 Aug 2021 08:29:59 +0800 Subject: [PATCH] Support for noUncheckedIndexedAccess tsconfig --- index.js | 14 ++++++++------ index.ts | 10 ++++++---- tsconfig.json | 2 ++ 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/index.js b/index.js index c9cea7f..f405b47 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,7 @@ var Graceful = /** @class */ (function () { process.removeListener('uncaughtException', Graceful.exceptionListener); } }, - enumerable: true, + enumerable: false, configurable: true }); Object.defineProperty(Graceful, "captureRejections", { @@ -40,7 +40,7 @@ var Graceful = /** @class */ (function () { process.removeListener('unhandledRejection', Graceful.rejectionListener); } }, - enumerable: true, + enumerable: false, configurable: true }); Graceful.on = function (signal, listener) { @@ -116,8 +116,9 @@ var Graceful = /** @class */ (function () { Graceful.updateRegistration = function () { if (Graceful.listeners.length && !Graceful.isRegistered) { var _loop_1 = function (deadlySignal) { - Graceful.signalsListeners[deadlySignal] = function () { return Graceful.onDeadlyEvent(deadlySignal); }; - process.on(deadlySignal, Graceful.signalsListeners[deadlySignal]); + var listener = function () { return Graceful.onDeadlyEvent(deadlySignal); }; + Graceful.signalsListeners[deadlySignal] = listener; + process.on(deadlySignal, listener); }; for (var _i = 0, _a = Graceful.DEADLY_SIGNALS; _i < _a.length; _i++) { var deadlySignal = _a[_i]; @@ -128,8 +129,9 @@ var Graceful = /** @class */ (function () { else if (!Graceful.listeners.length && Graceful.isRegistered) { for (var _b = 0, _c = Graceful.DEADLY_SIGNALS; _b < _c.length; _b++) { var deadlySignal = _c[_b]; - if (Graceful.signalsListeners[deadlySignal]) { - process.removeListener(deadlySignal, Graceful.signalsListeners[deadlySignal]); + var listener = Graceful.signalsListeners[deadlySignal]; + if (listener) { + process.removeListener(deadlySignal, listener); delete Graceful.signalsListeners[deadlySignal]; } } diff --git a/index.ts b/index.ts index df7f993..98c3c77 100644 --- a/index.ts +++ b/index.ts @@ -138,14 +138,16 @@ export default class Graceful { private static updateRegistration() { if (Graceful.listeners.length && !Graceful.isRegistered) { for (const deadlySignal of Graceful.DEADLY_SIGNALS) { - Graceful.signalsListeners[deadlySignal] = () => Graceful.onDeadlyEvent(deadlySignal); - process.on(deadlySignal as any, Graceful.signalsListeners[deadlySignal]); + const listener = () => Graceful.onDeadlyEvent(deadlySignal); + Graceful.signalsListeners[deadlySignal] = listener + process.on(deadlySignal as any, listener); } Graceful.isRegistered = true } else if (!Graceful.listeners.length && Graceful.isRegistered) { for (const deadlySignal of Graceful.DEADLY_SIGNALS) { - if (Graceful.signalsListeners[deadlySignal]) { - process.removeListener(deadlySignal as any, Graceful.signalsListeners[deadlySignal]); + const listener = Graceful.signalsListeners[deadlySignal] + if (listener) { + process.removeListener(deadlySignal, listener); delete Graceful.signalsListeners[deadlySignal]; } } diff --git a/tsconfig.json b/tsconfig.json index de9cf42..04b7698 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,8 @@ "strict": true, "alwaysStrict": true, "preserveConstEnums": true, + "noPropertyAccessFromIndexSignature": true, + "noUncheckedIndexedAccess": true, "sourceMap": false, "moduleResolution": "Node", "esModuleInterop": true,