From 1a47eaf0a175d057319cb4a5c57337ff4aa88376 Mon Sep 17 00:00:00 2001 From: KATT Date: Sat, 30 Sep 2023 21:19:06 +0200 Subject: [PATCH] cool --- src/tson.ts | 11 +++-------- src/types.ts | 9 --------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/src/tson.ts b/src/tson.ts index 9a5d92cb..e792f4ed 100644 --- a/src/tson.ts +++ b/src/tson.ts @@ -77,22 +77,17 @@ export function tsonStringifier(opts: TsonOptions): TsonStringifyFn { export function tsonSerializer(opts: TsonOptions): TsonSerializeFn { const handlers = (() => { - // warmup the type handlers const types = opts.types.map((handler) => { - const key = handler.key as TsonTypeHandlerKey | undefined; - const serialize = handler.serialize; - type Serializer = ( value: unknown, nonce: TsonNonce, walk: WalkFn, ) => TsonSerializedValue; - const $serialize: Serializer = serialize + const $serialize: Serializer = handler.serialize ? (value, nonce, walk): TsonTuple => [ - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - key!, - walk(serialize(value)), + handler.key as TsonTypeHandlerKey, + walk(handler.serialize(value)), nonce, ] : (value, _nonce, walk) => walk(value); diff --git a/src/types.ts b/src/types.ts index e9b1049d..a03940f9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -36,11 +36,6 @@ export interface TsonTransformerNone { */ key?: never; serialize?: never; - - /** - * Won't be deserialized nor serialized - */ - transform: false; } export interface TsonTransformerSerializeDeserialize< TValue, @@ -59,10 +54,6 @@ export interface TsonTransformerSerializeDeserialize< * JSON-serializable value */ serialize: (v: TValue) => TSerializedType; - /** - * Use a transformer to serialize and deserialize the value? - */ - transform?: true; } export type TsonTransformer =