cashscript icon indicating copy to clipboard operation
cashscript copied to clipboard

Further improve typings for 'unlock' functions

Open mr-zwets opened this issue 11 months ago • 1 comments

now it gives type hints without the aliases for the different arguments, and gives all the union types which makes everything hard to read:

transfer: (functionParameters_0: string | Uint8Array<ArrayBufferLike> | SignatureTemplate) => Unlocker
spend: (functionParameters_0: string | Uint8Array<ArrayBufferLike>, functionParameters_1: string | Uint8Array<ArrayBufferLike> | SignatureTemplate) => Unlocker

where we would want something like:

transfer: (recipientSig: SignatureType) => Unlocker
spend: (pk: PubKeyType, sig: SignatureType) => Unlocker

mr-zwets avatar Mar 26 '25 13:03 mr-zwets

Additionally, for type inference in the Contract constructor, it probably makes sense to mark the constructor params as readonly, so that it would be possible to do something like this without running into TS errors:

const inputs = ['a', 'b', 'c'] as const;
const contract = new Contract(p2pkhArtifact, inputs);

rkalis avatar Apr 11 '25 09:04 rkalis

We just updated this so that the types are clearer (BytesType instead of string | ... | ...). Unfortunately we're unable to use dynamic labels for the function parameter names (see https://github.com/microsoft/TypeScript/issues/44939).

rkalis avatar Aug 29 '25 09:08 rkalis