Open kayac-chang opened 10 months ago
Depending on the documentation, the enum schema should be
enum
{ enum: [ { struct: { className1: structSchema1 } }, { struct: { className2: structSchema2 } }, ... ] }
Suppose we have a schema like
const borsh_schema = { enum: [ { struct: { transfer: { struct: { recipient: 'string', amount: "u64", }, } } }, { struct: { deploy: { struct: { contract: { array: { type: "u8" } }, cbi_version: "u32", }, } } }, ], }
The type of schema will become (this is intended behavior)
const borsh_schema: { enum: ({ struct: { transfer: { struct: { recipient: string; amount: string; }; }; deploy?: undefined; }; } | { struct: { deploy: { struct: { contract: { array: { type: string; }; }; cbi_version: string; }; }; transfer?: undefined; }; })[]; }
But this will fail the type check when we want to pass schema to (de)serialize
deserialize(borsh_schema, bytes) // this will failed the type check
Typescript Playground: https://tsplay.dev/WPM05w
Enum works for me. You may be interested in borsher
@kayac-chang I did not understand the issue, could you please share a repo with the error so I can reproduce it and check on it?
Depending on the documentation, the
enum
schema should beSuppose we have a schema like
The type of schema will become (this is intended behavior)
But this will fail the type check when we want to pass schema to (de)serialize
Typescript Playground: https://tsplay.dev/WPM05w