interface ICustomResponse<T> {
success: boolean;
message?: string;
...T?
};
export const register = async (body: Body) => {
const { data } = await axios.post<
ICustomResponse <{ hasNickname?: boolean; hasEmail?: boolean }>
>('/user/register', body);
return data;
};
我想接收并使用
ICustomResponse
泛型,如上面的代码。
由于 success
和 message
几乎包含在所有函数中,我想静态添加值并接收其他属性作为泛型,我该怎么办?
这曾经是一个有用的答案,但后来却中箭了!