sinclairzx81 / typebox

Json Schema Type Builder with Static Type Resolution for TypeScript
Other
4.77k stars 152 forks source link

Value.Convert() doesn't work with nullable record #930

Closed woody146 closed 1 month ago

woody146 commented 1 month ago

My case is

const nullableRecord = Type.Union([Type.Record(Type.String(), Type.Any()), Type.Null()])
Value.Convert(nullableRecord, null)
> Uncaught TypeError: Cannot convert undefined or null to object

But change to

const nullableRecord = Type.Union([Type.Null(), Type.Record(Type.String(), Type.Any())])
Value.Convert(nullableRecord, null) // is oke
sinclairzx81 commented 1 month ago

@woody146 Hi, thanks for reporting.

This is a good find. Have pushed a quick fix for this on 0.32.35. If you run into any issues, feel free to ping on this thread.

All the best S