taquito
taquito copied to clipboard
How to type the result of contract.at when using compose ?
Hello 👋
First of all, thanks for the work your putting in Taquito !
this.toolkit = new TezosToolkit('...');
tezos.addExtension([new Tzip12Module(), new Tzip16Module()]);
const contract = await this.tezos.contract.at(
this.address,
compose(tzip12, tzip16),
);
// ↓↓↓ Property 'tzip12' does not exist on type 'ContractAbstraction<ContractProvider, DefaultMethods<ContractProvider>, DefaultMethodsObject<ContractProvider>, DefaultViews, DefaultContractViews, unknown>'
contract.tzip12().getTokenMetadata(itemId)
Property 'tzip12' does not exist on type 'ContractAbstraction<ContractProvider, DefaultMethods<ContractProvider>, DefaultMethodsObject<ContractProvider>, DefaultViews, DefaultContractViews, unknown>'
What is the correct type hint to help typescript understand the tzip12
method exists in contract
?
I tried this, but it does not work :
// ↓↓↓ Type 'ContractAbstraction<ContractProvider, DefaultMethods<ContractProvider>, DefaultMethodsObject<ContractProvider>, DefaultViews, DefaultContractViews, unknown> & { ...; } & { ...; }' is not assignable to type 'Tzip12ContractAbstraction | undefined'
this.contract: Tzip12ContractAbstraction = await this.tezos.contract.at(
this.address,
compose(tzip12, tzip16),
);
Thanks in advance !
I tried to reproduce your example locally but I'm missing some things. Can you share your complete example please?
Try just using a single extension; I don't think both are necessary as they use the same MetadataProvider:
Tezos.addExtension(new Tzip12Module());
Hey @egarson, thanks for your feedback and sorry for late.
Here you go : https://codesandbox.io/s/taquito-tzip12-typing-ve0ueo?file=/src/index.ts.
Thanks in advance !