Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 85db7c0

Browse files
fix: type check issues on encod/decode arguments
This commit intends to fix the issue reported on #136
1 parent f28e981 commit 85db7c0

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

‎src/context.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* eslint-disable @typescript-eslint/ban-types */
22

3-
export type SplitTypes<T, U> = U extends T ? U : Exclude<T, U>;
4-
export type SplitUndefined<T> = SplitTypes<T, undefined>;
3+
export type SplitTypes<T, U> = U extends T
4+
? Exclude<T, U> extends never ? T : Exclude<T, U>
5+
: T;
6+
7+
export type SplitUndefined<T> = SplitTypes<T, undefined>
58

69
export type ContextOf<ContextType> = ContextType extends undefined
710
? {}

‎src/decode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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,

‎src/decodeAsync.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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,

‎src/encode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /