Implement the generic ClassPublicKeys<T>
which returns all public keys of a class.
For example:
class A {
public str: string
protected num: number
private bool: boolean
getNum() {
return Math.random()
}
}
type publicKyes = ClassPublicKeys<A> // 'str' | 'getNum'
/* _____________ Your Code Here _____________ */
type ClassPublicKeys<C> = keyof C
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'
class A {
public str: string
protected num: number
private bool: boolean
constructor() {
this.str = 'naive'
this.num = 19260917
this.bool = true
}
getNum() {
return Math.random()
}
}
type cases = [
Expect<Equal<ClassPublicKeys<A>, 'str' | 'getNum'>>,
]
标签:Typescript,_____________,ClassPublicKeys,getNum,117,bool,str,type From: https://www.cnblogs.com/Answer1215/p/16927640.html