Skip to content

Commit 4c0bb04

Browse files
update createDefaultCodec to handle UnknownType
1 parent cd336a0 commit 4c0bb04

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"author": "Transcend Inc.",
33
"name": "@transcend-io/type-utils",
44
"description": "Small package containing useful typescript utilities.",
5-
"version": "1.8.3",
5+
"version": "1.8.4",
66
"homepage": "https://github.com/transcend-io/type-utils",
77
"repository": {
88
"type": "git",

src/codecTools/createDefaultCodec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const createDefaultCodec = <C extends t.Mixed>(
121121
}
122122

123123
// The default of an object type is an empty object
124-
if (codec instanceof t.ObjectType) {
124+
if (codec instanceof t.ObjectType || codec instanceof t.UnknownType) {
125125
return {} as t.TypeOf<C>;
126126
}
127127

src/tests/createDefaultCodec.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { createDefaultCodec } from '../codecTools';
66

77
chai.use(deepEqualInAnyOrder);
88

9-
describe.only('buildDefaultCodec', () => {
9+
describe('buildDefaultCodec', () => {
1010
it('should correctly build a default codec for null', () => {
1111
const result = createDefaultCodec(t.null);
1212
expect(result).to.equal(null);
@@ -44,6 +44,12 @@ describe.only('buildDefaultCodec', () => {
4444
expect(defaultCodec).to.deep.equal({});
4545
});
4646

47+
it('should correctly build a default codec for an UnknownType', () => {
48+
const codec = t.unknown;
49+
const defaultCodec = createDefaultCodec(codec);
50+
expect(defaultCodec).to.deep.equal({});
51+
});
52+
4753
it('should correctly build a default codec for a union with null', () => {
4854
const result = createDefaultCodec(t.union([t.string, t.null]));
4955
// should default to null if the union contains null

0 commit comments

Comments
 (0)