Typescript get names of fields but not properties (or at least get only)

I know in typescript I can do this, to get the names of properties:

type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
type NonFunctionProperties<T> = Pick<T, NonFunctionPropertyNames<T>>;

This worked great: (see here)

My only problem was when I changed my methods to properties (see here): (

Length(): number {return Math.sqrt(this.X * this.X + this.Y * this.Y) }

to

get Length(): number {return Math.sqrt(this.X * this.X + this.Y * this.Y) }

)Is there a way to exclude get-only properties or properties in general?

What I would need would be something like:

T[K] extends (GetOnlyProperty | Function)

instead of

T[K] extends Function


Read more here: https://stackoverflow.com/questions/67928288/typescript-get-names-of-fields-but-not-properties-or-at-least-get-only

Content Attribution

This content was originally published by trinalbadger587 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: