Skip to content

Commit

Permalink
Merge pull request #154 from fleet-sdk/arobsn/i152
Browse files Browse the repository at this point in the history
Fix types for `SColl[SColl[SByte]]` when passing `UInt8Array`
  • Loading branch information
arobsn authored Nov 25, 2024
2 parents 3d3abd8 + a47a5fd commit 2ebaa45
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/nasty-beans-count.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fleet-sdk/serializer": patch
---

Fix types for nested `SColl[SBytes]` creation.
6 changes: 6 additions & 0 deletions packages/serializer/src/types/constructors.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ describe("Constructor proxies types", () => {
[false, false]
]).data
).toMatchTypeOf<boolean[][]>();
expectTypeOf(
SColl(SColl(SByte), [Uint8Array.from([1, 2, 3]), Uint8Array.from([4, 5, 6])]).data
).toMatchTypeOf<Uint8Array[]>();
expectTypeOf(SColl(SColl(SByte), ["deadbeef", "cafe"]).data).toMatchTypeOf<
Uint8Array[]
>();

expectTypeOf(SPair(SInt(1), SBool(false)).data).toMatchTypeOf<[number, boolean]>();
expectTypeOf(SPair(SBool(true), SInt(1)).data).toMatchTypeOf<[boolean, number]>();
Expand Down
7 changes: 6 additions & 1 deletion packages/serializer/src/types/constructors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,16 @@ type SUnit = (value?: undefined) => SConstant<undefined, SUnitType>;
export const SUnit: SUnit = monoProxy(SUnitType, undefined, true);

type SColl = {
<D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;
<D, T extends SByteType>(
type: SConstructor<D, T>,
elements: ByteInput | D[]
): SConstant<Uint8Array, T>;
<D, T extends SByteType>(
type: SConstructor<D, T>,
elements: ByteInput[]
): SConstant<Uint8Array[], T>;

<D, T extends SType>(type: SConstructor<D, T>): SConstructor<D[], T>;
<D, T extends SType>(type: SConstructor<D, T>, elements: D[]): SConstant<D[], T>;
};

Expand Down

0 comments on commit 2ebaa45

Please sign in to comment.