diff --git a/src/typed-function.mjs b/src/typed-function.mjs index 55499f7..31c910e 100644 --- a/src/typed-function.mjs +++ b/src/typed-function.mjs @@ -1878,7 +1878,7 @@ function create () { if (existing) { if (options && options.override) { - to.conversionsTo.splice(existing.index, 1) + typed.removeConversion({ from: existing.from, to: conversion.to, convert: existing.convert }) } else { throw new Error( 'There is already a conversion from "' + conversion.from + '" to "' + diff --git a/test/conversion.test.js b/test/conversion.test.js index 690e6c0..5da72d3 100644 --- a/test/conversion.test.js +++ b/test/conversion.test.js @@ -101,6 +101,11 @@ describe('conversion', function () { it('should override a conversion using addConversions', function () { const typed2 = typed.create() + // we add an unrelated conversion to ensure we cannot misuse the internal .index + // (which is more like an auto incrementing id) + const conversionUnrelated = { from: 'string', to: 'boolean', convert: () => 'c' } + typed2.addConversion(conversionUnrelated) + const conversionA = { from: 'number', to: 'string', convert: () => 'a' } const conversionB = { from: 'number', to: 'string', convert: () => 'b' }