Skip to content

Commit fc6529f

Browse files
committed
Merge branch 'develop'
2 parents 479eb2e + dda4393 commit fc6529f

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# History
22

33

4+
## 2024-06-05, version 4.2.1
5+
6+
- Fix a bug in the new `override` option of method `addConversion`.
7+
8+
49
## 2024-06-05, version 4.2.0
510

611
- Extend methods `addConversion` and `addConversions` with a new option

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "typed-function",
3-
"version": "4.2.0",
3+
"version": "4.2.1",
44
"description": "Type checking for JavaScript functions",
55
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
66
"contributors": [

src/typed-function.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ function create () {
18781878

18791879
if (existing) {
18801880
if (options && options.override) {
1881-
to.conversionsTo.splice(existing.index, 1)
1881+
typed.removeConversion({ from: existing.from, to: conversion.to, convert: existing.convert })
18821882
} else {
18831883
throw new Error(
18841884
'There is already a conversion from "' + conversion.from + '" to "' +

test/conversion.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ describe('conversion', function () {
101101
it('should override a conversion using addConversions', function () {
102102
const typed2 = typed.create()
103103

104+
// we add an unrelated conversion to ensure we cannot misuse the internal .index
105+
// (which is more like an auto incrementing id)
106+
const conversionUnrelated = { from: 'string', to: 'boolean', convert: () => 'c' }
107+
typed2.addConversion(conversionUnrelated)
108+
104109
const conversionA = { from: 'number', to: 'string', convert: () => 'a' }
105110
const conversionB = { from: 'number', to: 'string', convert: () => 'b' }
106111

0 commit comments

Comments
 (0)