From 4a443ac9a635e56da2a219c0bfdd46787449d202 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Thu, 10 Oct 2024 06:57:01 +1100 Subject: [PATCH] fix: `this`reference Was broken via #469 --- lib/types.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/types.js b/lib/types.js index ee17b5ef..7a8331e0 100644 --- a/lib/types.js +++ b/lib/types.js @@ -1243,7 +1243,7 @@ function generateProjectionIndexer(projectionFn) { }; } -function generateDefaultIndexer(types) { +function generateDefaultIndexer(types, self) { const dynamicBranches = []; const bucketIndices = {}; @@ -1271,7 +1271,7 @@ function generateDefaultIndexer(types) { } else { let bucket = getTypeBucket(type); if (bucketIndices[bucket] !== undefined) { - throw new Error(`ambiguous unwrapped union: ${j(this)}`); + throw new Error(`ambiguous unwrapped union: ${j(self)}`); } bucketIndices[bucket] = index; } @@ -1314,7 +1314,7 @@ class UnwrappedUnionType extends UnionType { } this._getIndex = _projectionFn ? generateProjectionIndexer(_projectionFn) - : generateDefaultIndexer(this.types); + : generateDefaultIndexer(this.types, this); Object.freeze(this); }