@@ -44,6 +44,18 @@ const hasInnerError = (error: unknown): error is { innerError: unknown } =>
44
44
const innerErrorHasData = ( innerError : unknown ) : innerError is { data : unknown } =>
45
45
typeof innerError === 'object' && innerError !== null && 'data' in innerError ;
46
46
47
+ const isNativeNonSerializableType = ( obj : unknown ) : boolean => {
48
+ if ( typeof obj === 'undefined' || typeof obj === 'bigint' ) return true ;
49
+ if ( typeof obj === 'object' && obj !== null ) {
50
+ if ( obj instanceof Date ) return true ;
51
+ if ( obj instanceof Error ) return true ;
52
+ if ( obj instanceof Map ) return true ;
53
+ if ( obj instanceof Set ) return true ;
54
+ if ( ArrayBuffer . isView ( obj ) ) return true ;
55
+ }
56
+ return false ;
57
+ } ;
58
+
47
59
export const toSerializableObject = ( obj : unknown , options : ToSerializableObjectOptions = { } ) : unknown => {
48
60
if ( PLAIN_TYPES . has ( typeof obj ) ) return obj ;
49
61
const { transformationTypeKey = defaultTransformationTypeKey , serializeKey = defaultTransformKey } = options ;
@@ -110,7 +122,9 @@ export const toSerializableObject = (obj: unknown, options: ToSerializableObject
110
122
} ;
111
123
112
124
const fromSerializableObjectUnknown = ( obj : unknown , options : FromSerializableObjectOptions = { } ) : unknown => {
113
- if ( PLAIN_TYPES . has ( typeof obj ) ) return obj ;
125
+ if ( PLAIN_TYPES . has ( typeof obj ) ) return obj ; // no-op for plain types
126
+ if ( isNativeNonSerializableType ( obj ) ) return obj ; // no-op for native types
127
+
114
128
if ( typeof obj === 'object' ) {
115
129
if ( obj === null ) return null ;
116
130
if ( Array . isArray ( obj ) ) {
0 commit comments