@@ -44,6 +44,18 @@ const hasInnerError = (error: unknown): error is { innerError: unknown } =>
4444const innerErrorHasData = ( innerError : unknown ) : innerError is { data : unknown } =>
4545 typeof innerError === 'object' && innerError !== null && 'data' in innerError ;
4646
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+
4759export const toSerializableObject = ( obj : unknown , options : ToSerializableObjectOptions = { } ) : unknown => {
4860 if ( PLAIN_TYPES . has ( typeof obj ) ) return obj ;
4961 const { transformationTypeKey = defaultTransformationTypeKey , serializeKey = defaultTransformKey } = options ;
@@ -110,7 +122,9 @@ export const toSerializableObject = (obj: unknown, options: ToSerializableObject
110122} ;
111123
112124const 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+
114128 if ( typeof obj === 'object' ) {
115129 if ( obj === null ) return null ;
116130 if ( Array . isArray ( obj ) ) {
0 commit comments