Last active
July 19, 2024 11:01
-
-
Save soal/f269ff18862e04b44d3b4b1781a63506 to your computer and use it in GitHub Desktop.
Creates type recursively excluding functions from given type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ExcludeFunctions<T> = { | |
// We need to map over the keys directly to preserve optionality. We filter with "as" | |
[K in keyof T as T[K] extends Function ? never : K]: | |
// Exclude undefined from the check to properly handle optional properties | |
Exclude<T[K], undefined> extends Array<infer E> | |
? Array<ExcludeFunctions<E>> | |
: Exclude<T[K], undefined> extends Record<string, any> | |
? ExcludeFunctions<T[K]> | |
: T[K]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment