Closed OliverJAsh closed 1 year ago
Looks similarly fixable by taking the Sum
instance as an argument in deserialize
:
- deserialize<Weather>()
+ deserialize(Weather)
A drop-in test case:
diff --git a/test/unit/index.ts b/test/unit/index.ts
index 142de4b..4be69d9 100644
--- a/test/unit/index.ts
+++ b/test/unit/index.ts
@@ -74,5 +74,16 @@ describe("index", () => {
}),
)
})
+
+ it('deserializations are reference-equal', () => {
+ type Weather = Member<"Sun"> | Member<"Rain", 123>
+ const Weather = create<Weather>()
+
+ const sun = Weather.mk.Sun
+ expect(deserialize<Weather>()(serialize(sun))).toEqual(sun)
+
+ const rain = Weather.mk.Rain(123)
+ expect(deserialize<Weather>()(serialize(rain))).toEqual(rain)
+ })
})
})
As expected, sun
fails but rain
succeeds. (They should both succeed.)
Related to https://github.com/unsplash/sum-types/issues/35.
This test fails: