如何在通用界面中添加静态属性

问题描述 投票:0回答:1
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
几乎包含在所有函数中,我想静态添加值并接收其他属性作为泛型,我该怎么办?

typescript
1个回答
1
投票

这曾经是一个有用的答案,但后来却中箭了!

© www.soinside.com 2019 - 2024. All rights reserved.