diff --git a/src/context.ts b/src/context.ts index c83d9720..85b931d1 100644 --- a/src/context.ts +++ b/src/context.ts @@ -1,6 +1,9 @@ /* eslint-disable @typescript-eslint/ban-types */ -export type SplitTypes = U extends T ? U : Exclude; +export type SplitTypes = U extends T + ? Exclude extends never ? T : Exclude + : T; + export type SplitUndefined = SplitTypes; export type ContextOf = ContextType extends undefined diff --git a/src/decode.ts b/src/decode.ts index 1fcaea3e..f1c0ac0e 100644 --- a/src/decode.ts +++ b/src/decode.ts @@ -42,11 +42,11 @@ export const defaultDecodeOptions: DecodeOptions = {}; * * This is a synchronous decoding function. See other variants for asynchronous decoding: `decodeAsync()`, `decodeStream()`, `decodeArrayStream()`. */ -export function decode( +export function decode( buffer: ArrayLike | ArrayBuffer, options: DecodeOptions> = defaultDecodeOptions as any, ): unknown { - const decoder = new Decoder( + const decoder = new Decoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxStrLength, diff --git a/src/decodeAsync.ts b/src/decodeAsync.ts index e840b11b..ac88e45a 100644 --- a/src/decodeAsync.ts +++ b/src/decodeAsync.ts @@ -9,7 +9,7 @@ export async function decodeAsync( ): Promise { const stream = ensureAsyncIterabe(streamLike); - const decoder = new Decoder( + const decoder = new Decoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxStrLength, @@ -27,7 +27,7 @@ export function decodeArrayStream( ) { const stream = ensureAsyncIterabe(streamLike); - const decoder = new Decoder( + const decoder = new Decoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxStrLength, @@ -46,7 +46,7 @@ export function decodeStream( ) { const stream = ensureAsyncIterabe(streamLike); - const decoder = new Decoder( + const decoder = new Decoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxStrLength, diff --git a/src/encode.ts b/src/encode.ts index 95a80204..1fc01c78 100644 --- a/src/encode.ts +++ b/src/encode.ts @@ -43,11 +43,11 @@ const defaultEncodeOptions: EncodeOptions = {}; * * 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`. */ -export function encode( +export function encode( value: unknown, options: EncodeOptions> = defaultEncodeOptions as any, ): Uint8Array { - const encoder = new Encoder( + const encoder = new Encoder( options.extensionCodec, (options as typeof options & { context: any }).context, options.maxDepth,