Skip to content

update createDefaultCodec to handle object types correctly#34

Merged
abrantesarthur merged 3 commits intomainfrom
createDefaultCodec
Jan 19, 2025
Merged

update createDefaultCodec to handle object types correctly#34
abrantesarthur merged 3 commits intomainfrom
createDefaultCodec

Conversation

@abrantesarthur
Copy link
Contributor

@abrantesarthur abrantesarthur commented Jan 19, 2025

  • before, createDefaultCodec returned null for object types. Now, it returns an empty object.

@abrantesarthur abrantesarthur requested review from a team and anotherminh January 19, 2025 14:14

// The default of an object type is an empty object
if (codec instanceof t.ObjectType) {
return {} as t.TypeOf<C>;
Copy link
Member

@dipack95 dipack95 Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be useful to do this for t.UnknownRecord too since t.object is deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed another PR here #35

Copy link
Member

@dipack95 dipack95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

it('should correctly build a default codec for an object', () => {
const codec = t.object;
const defaultCodec = createDefaultCodec(codec);
expect(defaultCodec).to.deep.equal({});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this also enforce that there are no keys in the resulting object?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! The test fails if the object has any keys.

@abrantesarthur abrantesarthur merged commit cac2f41 into main Jan 19, 2025
11 checks passed
@abrantesarthur abrantesarthur deleted the createDefaultCodec branch January 19, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants