Created
April 10, 2021 13:37
-
-
Save Ascor8522/78d764aa7483329d100820cc79dbfac9 to your computer and use it in GitHub Desktop.
A TypeScript utility type that only extract the attributes of a type, and ignores the methods.
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
/** | |
* Extracts the attributes of a type, and ignores the methods. | |
* Can be used in a constructor, when passing a destructured object of the same type. | |
* Requires TypeScript 4.1+ | |
*/ | |
export type Attributes<T> = { | |
[K in keyof T as T[K] extends Function ? never : K]: T[K] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment