Skip to content

Instantly share code, notes, and snippets.

@Ascor8522
Created April 10, 2021 13:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ascor8522/78d764aa7483329d100820cc79dbfac9 to your computer and use it in GitHub Desktop.
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.
/**
* 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