feat(composeTxOptionsFactory): auto narrow post condition type

This commit is contained in:
c4605
2025-03-14 14:06:38 +01:00
parent 33a275d36e
commit 94a2d11c7f

View File

@@ -14,26 +14,25 @@ import type {
ParameterObjOfDescriptor, ParameterObjOfDescriptor,
} from "./contractBase"; } from "./contractBase";
type PostCondition = type PostConditionPlain = FungiblePostCondition | StxPostCondition;
| FungiblePostCondition type PostConditionWire = FungiblePostConditionWire | STXPostConditionWire;
| StxPostCondition type PostCondition = PostConditionPlain | PostConditionWire;
| FungiblePostConditionWire
| STXPostConditionWire;
export interface ContractCallOptions { export interface ContractCallOptions<PC extends PostCondition> {
contractAddress: string; contractAddress: string;
contractName: string; contractName: string;
functionName: string; functionName: string;
functionArgs: ClarityValue[]; functionArgs: ClarityValue[];
anchorMode: AnchorMode; anchorMode: AnchorMode;
postConditionMode: PostConditionMode; postConditionMode: PostConditionMode;
postConditions?: PostCondition[]; postConditions?: PC[];
} }
export type ComposeTxOptionsFn<Contracts extends ContractBaseType> = < export type ComposeTxOptionsFn<Contracts extends ContractBaseType> = <
T extends StringOnly<keyof Contracts>, T extends StringOnly<keyof Contracts>,
F extends StringOnly<keyof Contracts[T]>, F extends StringOnly<keyof Contracts[T]>,
Descriptor extends Contracts[T][F] Descriptor extends Contracts[T][F],
PC extends PostCondition
>( >(
contractName: T, contractName: T,
functionName: F, functionName: F,
@@ -42,9 +41,9 @@ export type ComposeTxOptionsFn<Contracts extends ContractBaseType> = <
: never, : never,
options?: { options?: {
deployerAddress?: string; deployerAddress?: string;
postConditions?: PostCondition[]; postConditions?: PC[];
} }
) => ContractCallOptions; ) => ContractCallOptions<PC>;
export const composeTxOptionsFactory = export const composeTxOptionsFactory =
<T extends ContractBaseType>( <T extends ContractBaseType>(