Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
josdejong committed Jun 5, 2024
2 parents 479eb2e + dda4393 commit fc6529f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# History


## 2024-06-05, version 4.2.1

- Fix a bug in the new `override` option of method `addConversion`.


## 2024-06-05, version 4.2.0

- Extend methods `addConversion` and `addConversions` with a new option
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typed-function",
"version": "4.2.0",
"version": "4.2.1",
"description": "Type checking for JavaScript functions",
"author": "Jos de Jong <wjosdejong@gmail.com> (https://github.com/josdejong)",
"contributors": [
Expand Down
2 changes: 1 addition & 1 deletion src/typed-function.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "' +
Expand Down
5 changes: 5 additions & 0 deletions test/conversion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' }

Expand Down

0 comments on commit fc6529f

Please sign in to comment.