Exclude object keys by their value type in TypeScript
问题 I want to map an object type to a subtype that includes only keys whose values are of a specific type. For example, something like ExtractNumeric<T> , where ExtractNumeric<{ str: string, num: number }> should be equivalent to the type: { num: number } I've tried this, but it does not work: type ExtractNumeric<T> = { [k in keyof T]: T[k] extends number ? T[k] : never } This snippet throws a type error: let obj: ExtractNumeric<{ str: string, num: number }> = { num: 1 } Because although the str