ClassPublicKeys

Challenge

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'

Solution

Zur Lösung dieses Problems können wir einfach den keyof-Operator nutzen:

type ClassPublicKeys<T> = keyof T;

References

Keyof Type Operator