File tree Expand file tree Collapse file tree 4 files changed +11
-8
lines changed
Expand file tree Collapse file tree 4 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 11/* eslint-disable @typescript-eslint/ban-types */
22
3- export type SplitTypes < T , U > = U extends T ? U : Exclude < T , U > ;
3+ export type SplitTypes < T , U > = U extends T
4+ ? Exclude < T , U > extends never ? T : Exclude < T , U >
5+ : T ;
6+
47export type SplitUndefined < T > = SplitTypes < T , undefined > ;
58
69export type ContextOf < ContextType > = ContextType extends undefined
Original file line number Diff line number Diff line change @@ -42,11 +42,11 @@ export const defaultDecodeOptions: DecodeOptions = {};
4242 *
4343 * This is a synchronous decoding function. See other variants for asynchronous decoding: `decodeAsync()`, `decodeStream()`, `decodeArrayStream()`.
4444 */
45- export function decode < ContextType > (
45+ export function decode < ContextType = undefined > (
4646 buffer : ArrayLike < number > | ArrayBuffer ,
4747 options : DecodeOptions < SplitUndefined < ContextType > > = defaultDecodeOptions as any ,
4848) : unknown {
49- const decoder = new Decoder < ContextType > (
49+ const decoder = new Decoder (
5050 options . extensionCodec ,
5151 ( options as typeof options & { context : any } ) . context ,
5252 options . maxStrLength ,
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export async function decodeAsync<ContextType>(
99) : Promise < unknown > {
1010 const stream = ensureAsyncIterabe ( streamLike ) ;
1111
12- const decoder = new Decoder < ContextType > (
12+ const decoder = new Decoder (
1313 options . extensionCodec ,
1414 ( options as typeof options & { context : any } ) . context ,
1515 options . maxStrLength ,
@@ -27,7 +27,7 @@ export function decodeArrayStream<ContextType>(
2727) {
2828 const stream = ensureAsyncIterabe ( streamLike ) ;
2929
30- const decoder = new Decoder < ContextType > (
30+ const decoder = new Decoder (
3131 options . extensionCodec ,
3232 ( options as typeof options & { context : any } ) . context ,
3333 options . maxStrLength ,
@@ -46,7 +46,7 @@ export function decodeStream<ContextType>(
4646) {
4747 const stream = ensureAsyncIterabe ( streamLike ) ;
4848
49- const decoder = new Decoder < ContextType > (
49+ const decoder = new Decoder (
5050 options . extensionCodec ,
5151 ( options as typeof options & { context : any } ) . context ,
5252 options . maxStrLength ,
Original file line number Diff line number Diff line change @@ -43,11 +43,11 @@ const defaultEncodeOptions: EncodeOptions = {};
4343 *
4444 * The returned buffer is a slice of a larger `ArrayBuffer`, so you have to use its `#byteOffset` and `#byteLength` in order to convert it to another typed arrays including NodeJS `Buffer`.
4545 */
46- export function encode < ContextType > (
46+ export function encode < ContextType = undefined > (
4747 value : unknown ,
4848 options : EncodeOptions < SplitUndefined < ContextType > > = defaultEncodeOptions as any ,
4949) : Uint8Array {
50- const encoder = new Encoder < ContextType > (
50+ const encoder = new Encoder (
5151 options . extensionCodec ,
5252 ( options as typeof options & { context : any } ) . context ,
5353 options . maxDepth ,
You can’t perform that action at this time.
0 commit comments