admin管理员组文章数量:1390204
When using the viem
library's createWalletClient
function, you can optionally provide an account
parameter (to hoist it), and thereafter it's not needed to be specified on calls like walletClient.writeContract()
.
In Typescript, viem
exports a WalletClient
type, but it is defined as having its account
be optional. I have an helper function that always returns a WalletClient object with account
set. How can I annotate the helper function so all calling modules know the account
is already specified, and typescript stops telling me to add it into subsequent writeContract()
calls?
The viem
WalletClient
type does take some generics parameters, but I cannot figure a concise way to specify "the account is set to an address value" using them.
When using the viem
library's createWalletClient
function, you can optionally provide an account
parameter (to hoist it), and thereafter it's not needed to be specified on calls like walletClient.writeContract()
.
In Typescript, viem
exports a WalletClient
type, but it is defined as having its account
be optional. I have an helper function that always returns a WalletClient object with account
set. How can I annotate the helper function so all calling modules know the account
is already specified, and typescript stops telling me to add it into subsequent writeContract()
calls?
The viem
WalletClient
type does take some generics parameters, but I cannot figure a concise way to specify "the account is set to an address value" using them.
1 Answer
Reset to default 0For a WalletClient
that has an RPC connection (Transport), target chain, and address defined, the following type definition creates an alias for that:
export type ConnectedWalletClient = WalletClient<Transport, Chain, Account, undefined>
Having that be the type that the helper function returns, and being an exported type then allows other modules to use ConnectedWalletClient
as a short alias, and have Typescript not require specifying the account parameter on subsequent writeContract
calls.
本文标签: Typescript type for viem WalletClient with quotaccountquot definedStack Overflow
版权声明:本文标题:Typescript type for viem WalletClient with "account" defined? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744579818a2613850.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论