我想省略一个接口中的所有函数
interface Human {
name: string;
age: number;
walk: () => void;
talk: (word: string) => Promise<void>
}
type HumanWithoutFunctions = RemoveFunctions<Human>
/* expected result:
HumanWithoutFunctions {
name: string;
age: number;
}
*/
给你:
type RemoveFunctions<T> = {
[K in keyof T as T[K] extends Function ? never : K]: T[K]
}
游乐场