@@ -22,17 +22,10 @@ export class Encoder {
2222 this . encodeBoolean ( object ) ;
2323 } else if ( typeof object === "number" ) {
2424 this . encodeNumber ( object ) ;
25-
26- // eslint-disable-next-line valid-typeof
27- } else if ( typeof object === "bigint" ) {
28- this . encodeBigInt ( object ) ;
2925 } else if ( typeof object === "string" ) {
3026 this . encodeString ( object ) ;
31- } else if ( typeof object === "object" ) {
32- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33- this . encodeObject ( object ! , depth ) ;
3427 } else {
35- throw new Error ( `Unrecognized object: ${ Object . prototype . toString . apply ( object ) } ` ) ;
28+ this . encodeObject ( object , depth ) ;
3629 }
3730 }
3831
@@ -118,11 +111,6 @@ export class Encoder {
118111 }
119112 }
120113
121- encodeBigInt ( _object : bigint ) {
122- // BigInt literals is not available here!
123- throw new Error ( "BigInt is not yet implemented!" ) ;
124- }
125-
126114 encodeString ( object : string ) {
127115 const byteLength = utf8Count ( object ) ;
128116 if ( byteLength < 32 ) {
@@ -149,7 +137,7 @@ export class Encoder {
149137 this . pos += byteLength ;
150138 }
151139
152- encodeObject ( object : object , depth : number ) {
140+ encodeObject ( object : unknown , depth : number ) {
153141 // try to encode objects with custom codec first of non-primitives
154142 const ext = this . extensionCodec . tryToEncode ( object ) ;
155143 if ( ext != null ) {
@@ -158,8 +146,11 @@ export class Encoder {
158146 this . encodeBinary ( object ) ;
159147 } else if ( Array . isArray ( object ) ) {
160148 this . encodeArray ( object , depth ) ;
161- } else {
149+ } else if ( typeof object === "object" ) {
162150 this . encodeMap ( object as Record < string , unknown > , depth ) ;
151+ } else {
152+ // symbol, function and other special object come here unless extensionCodec handles them.
153+ throw new Error ( `Unrecognized object: ${ Object . prototype . toString . apply ( object ) } ` ) ;
163154 }
164155 }
165156
0 commit comments