To make it possible, you can utilize the Exclude
method with a generic type:
type AllGetters<T> = {
[k in keyof T]: Exclude<T[k], Function>
}
class A implements AllGetters<A> {
// simple properties: OK
a: string = 'foo';
b: number = 1;
// type error: type '() => number' is not assignable to type 'never'.
c(): number {
return 2;
}
// getter: OK
get d(): string {
return 'hi';
}
// getter: not OK because it returns a function
// type error: type 'Function' is not assignable to type 'never'.
get e(): Function {
return console.log;
}
}
Points to consider:
- There is no distinction in type between a simple property and a getter; as long as all actions are getters, it should meet your criteria.
- A getter that returns a function is also not permitted, as there is no difference in type from a method.
Playground Link