Error in Schema Transformation: Mismatch in Expected Types for Decoding and Encoding Functions
what is wrong w/ this simple schema:
I get this error:
I think the problem is in the encoding
export const ItemHistoryData = S.Array(
S.Tuple(S.DateFromString, S.Number, S.BigInt).pipe(S.transform(
S.Struct({
volume: S.Tuple(S.Date, S.BigInt),
price: S.Tuple(S.Date, S.BigInt),
}),
{
decode: ([date, price, volume]) => ({
volume: Tuple.make(date, volume),
price: Tuple.make(date, price),
}),
encode: ({ volume: [date, volume], price: [_, price] }) => Tuple.make(volume, price, date),
strict: true,
}
), S.asSchema),
);export const ItemHistoryData = S.Array(
S.Tuple(S.DateFromString, S.Number, S.BigInt).pipe(S.transform(
S.Struct({
volume: S.Tuple(S.Date, S.BigInt),
price: S.Tuple(S.Date, S.BigInt),
}),
{
decode: ([date, price, volume]) => ({
volume: Tuple.make(date, volume),
price: Tuple.make(date, price),
}),
encode: ({ volume: [date, volume], price: [_, price] }) => Tuple.make(volume, price, date),
strict: true,
}
), S.asSchema),
);I get this error:
Argument of type '{ decode: ([date, price, volume]: readonly [Date, number, bigint]) => { volume: [Date, bigint]; price: [Date, number]; }; encode: ({ volume: [date, volume], price: [_, price] }: { readonly volume: readonly [string, string]; readonly price: readonly [string, string]; }) => [...]; strict: true; }' is not assignable to parameter of type '{ readonly decode: (fromA: readonly [Date, number, bigint], fromI: readonly [string, number, string]) => { readonly volume: readonly [string, string]; readonly price: readonly [string, string]; }; readonly encode: (toI: { ...; }, toA: { ...; }) => readonly [...]; readonly strict?: true; } | { ...; }'.
Type at position 0 in source is not compatible with type at position 0 in target.
The types of 'decode(...).volume' are incompatible between these types.
Type 'Date' is not assignable to type 'string'.deno-ts(2345)Argument of type '{ decode: ([date, price, volume]: readonly [Date, number, bigint]) => { volume: [Date, bigint]; price: [Date, number]; }; encode: ({ volume: [date, volume], price: [_, price] }: { readonly volume: readonly [string, string]; readonly price: readonly [string, string]; }) => [...]; strict: true; }' is not assignable to parameter of type '{ readonly decode: (fromA: readonly [Date, number, bigint], fromI: readonly [string, number, string]) => { readonly volume: readonly [string, string]; readonly price: readonly [string, string]; }; readonly encode: (toI: { ...; }, toA: { ...; }) => readonly [...]; readonly strict?: true; } | { ...; }'.
Type at position 0 in source is not compatible with type at position 0 in target.
The types of 'decode(...).volume' are incompatible between these types.
Type 'Date' is not assignable to type 'string'.deno-ts(2345)I think the problem is in the encoding
