TS一些懒得记的类型写法

1、Promise 返回类型

import store from '@/store';
import { useGetItem } from '@/hooks//useStorage';
export const useSign = (params: {
    message: string;
    timestamp?: number;
    walletAddress?: string;
}): Promise<{
    message: string;
    sign: string;
    timestamp: number;
    walletAddress?: string;
}> => {
    params.timestamp = new Date().getTime();
    params.walletAddress = store.getState().user.walletAddress || useGetItem('walletconnect').accounts[0] || '';
    const { message, timestamp, walletAddress } = params;
    return new Promise((r, j) => {
        let web3 = store.getState().web3.web3 || '';
        if(!web3) {
            j('provider is not exist');
        }
        let sign = web3.eth.sign
        sign(web3.utils.utf8ToHex(message), walletAddress, (error: any, sign: any) => {
            if (sign) r({ message, sign, timestamp, walletAddress })
            else j(error)
        })
    })
}

2、获取对象类型

const params: {
    sign: string;
    message: string;
    cellId: string;
    sort?: number;
    videoUrl?: string;
    imageUrl?: string;
    imageFile?: any
} = {
    sign: res.sign,
    message: res.message,
    cellId: props.cellId,
    sort: props.sort || 0,
    imageFile: file.current || undefined,
    imageUrl: imageUrl.current || undefined,
    videoUrl: videoUrl.current || undefined
}
const formData = new FormData()
Object.keys(params).forEach((key: string) => {
    formData.append(key, params[key as keyof typeof params])
})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值