假设我想创建一个UserResponse
类型,看起来像这样:
type UserResponse = {
data: User,
meta: Meta
}
我怎样才能使Response
类型更通用,这样我就不必为其他响应类型重新创建相同的结构,其中只有data
属性的类型发生了变化?
所以创建一个新类型看起来像这样:
type ArticleResponse = Response<Article>
就这么简单:
interface Response<T> {
data: T,
meta: Meta
}
type ArticleResponse = Response<Article>;
type UserResponse = Response<User>;