Open yunliuyan opened 11 months ago
这个是给大伙开心的,hhh
type ClassPublicKeys<T> = keyof T
// 实现一个通用Last<T>,它接受一个数组T并返回其最后一个元素的类型。
type ClassPublicKeys<T> = keyof T;
class A {
public str: string
protected num: number
private bool: boolean
getNum() {
return Math.random()
}
}
type publicKyes = ClassPublicKeys<A> // 'str' | 'getNum'
let a: publicKyes = 'bool'
type ClassPublicKeys<T> = keyof T;
type publicKyes = ClassPublicKeys<A> // 'str' | 'getNum'
ClassPublicKeys
![#utils](https://img.shields.io/badge/-%23utils-999)
Implement the generic
ClassPublicKeys<T>
which returns all public keys of a class.For example: