Reputation: 10412
I want to Omit all functions from an interface
interface Human {
name: string;
age: number;
walk: () => void;
talk: (word: string) => Promise<void>
}
type HumanWithoutFunctions = RemoveFunctions<Human>
/* expected result:
HumanWithoutFunctions {
name: string;
age: number;
}
*/
Upvotes: 2
Views: 142
Reputation: 23795
Here you go:
type RemoveFunctions<T> = {
[K in keyof T as T[K] extends Function ? never : K]: T[K]
}
Upvotes: 2