Skip to content
This repository has been archived by the owner on Feb 16, 2021. It is now read-only.

Interface filters additional props when props contain a struct #245

Closed
zaim opened this issue Aug 17, 2016 · 3 comments · Fixed by #246
Closed

Interface filters additional props when props contain a struct #245

zaim opened this issue Aug 17, 2016 · 3 comments · Fixed by #246
Labels

Comments

@zaim
Copy link

zaim commented Aug 17, 2016

Version: 3.2.11

As per documentation, an interface should not filter additional props unless strict = true. However, when an interface contains a struct member (or, I believe, when there are non-identity types), additional props do get filtered out.

Here's a minimal console.log test:

const t = require('tcomb')

const Point = t.struct({
  x: t.Number,
  y: t.Number
})

const PointInterface = t.inter({
  x: t.Number,
  y: t.Number
})

const HydrateInterface = t.inter({
  point: Point
})


console.log(PointInterface({
  x: 1,
  y: 2,
  extra: 3
}))

// Expected:
// { x: 1, y: 2, extra: 3 }
//
// Output (correct):
// { x: 1, y: 2, extra: 3 }


console.log(HydrateInterface({
  point: { x: 1, y: 2 },
  extra: 3
}))

// Expected:
// { point: Struct { x: 1, y: 2 }, extra: 3 }
//
// Output (incorrect):
// { point: Struct { x: 1, y: 2 } }
//
// The additional prop "extra" should not be filtered out
@zaim
Copy link
Author

zaim commented Aug 17, 2016

I believe this has to do with hydration and idempotency checking. If given an actual Point instance, it works as expected:

console.log(HydrateInterface({
  point: Point({ x: 1, y: 2 }),
  extra: 3
}))

// Output:
// { point: Struct { x: 1, y: 2 }, extra: 3 }

@gcanti gcanti added the bug label Aug 17, 2016
@gcanti
Copy link
Owner

gcanti commented Aug 17, 2016

@zaim thanks for the detailed report, going to fix this

@gcanti
Copy link
Owner

gcanti commented Aug 17, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants