ts泛型接口
http://ts.xcatliu.com/introduction/index.html 基础
视频
https://study.163.com/course/courseLearn.htm?courseId=1211003811&lessonId=1281989285&utm_medium=androidShare&utm_campaign=share&utm_content=courseLearn&utm_u=1510937655&utm_source=weixin
https://study.163.com/course/introduction/1211003811.htm?courseId=1211003811&shareLessonId=1281989285&utm_medium=androidShare&utm_campaign=share&utm_content=courseLearn&utm_u=1510937655&utm_source=weixin&_trace_c_p_k2_=94a525fae35043c89e2fea3081c53829
export class User { id?: number name: string age: number constructor (id:number, name:string, age:number) { this.id = id this.name = name this.age = age } } export interface Ibase<T>{ data:T[] add: (params: Array<User>) => Promise<User[]> } export class Getdata implements Ibase<User> { data: Array<User> = [] async add (user:Array<User>): Promise<User[]> { this.data = user return await user } }
调用
const sdsd:Getdata = new Getdata()
const dsfsdf = [
{
id: 1,
name: '123123',
age: 10
},
{
id: 2,
name: '123123',
age: 10
},
{
id: 3,
name: '123123',
age: 10
}
]
// sdsd.add(dsfsdf)
sdsd.add(dsfsdf).then((res:any) => {
console.log(res)
})
}
本文来自博客园,作者:zjxgdq,转载请注明原文链接:https://www.cnblogs.com/zjxzhj/p/15973273.html