ts重难点泛型总结
1.泛型 generics 定义返回任意类型的函数function echo<T>(arg: T): T { return arg}const res = echo(true)function swap<T, U>(tuple:[T, U]): [U, T] { return [tuple[1], tuple[0]]}const result2 = swap(['string', 123])// result2[1].会弹出提示可以调用这里面的方法
原创
2021-01-12 16:50:29 ·
387 阅读 ·
0 评论