Skip to content

Utility type to select only properties/methods/decorators #49564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks done
TheColorRed opened this issue Jun 15, 2022 · 2 comments
Closed
5 tasks done

Utility type to select only properties/methods/decorators #49564

TheColorRed opened this issue Jun 15, 2022 · 2 comments
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript

Comments

@TheColorRed
Copy link

Suggestion

πŸ” Search Terms

  • Utility Pick by Type
  • Utility Pick by Decorator

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Have additional Utility types that acts similar to Pick but allows to pick methods, properties, decorators.

πŸ“ƒ Motivating Example

This allows for a simpler way to get only properties, methods or specific items by decorator to create a new type.

export class MyClass {
  a: string;
  private b: number;
  @Input() color: string = 'red';

  c(){}
  protected d(){}
}

export type MyProperties = PickProperties<MyClass>;           // { a: string; b: number; color: string; }
export type MyProperties = PickProperties<MyClass, 'public'>; // { a: string; color: string; }

export type MyMethods = PickMethods<MyClass>;                 // { c: Function, d: Function; }
export type MyMethods = PickMethods<MyClass, 'protected'>;    // { d: Function; }

export type MyDecorators = PickDecorators<MyClass, 'Input'>;  // { color: string; }

πŸ’» Use Cases

This would be helpful for picking properties/methods in classes with lots of items so that you wouldn't have to specifically define all the items to Omit or Pick individually.

@RyanCavanaugh RyanCavanaugh added Suggestion An idea for TypeScript Declined The issue was declined as something which matches the TypeScript vision labels Jun 15, 2022
@RyanCavanaugh
Copy link
Member

We don't add new utility types that aren't required for declaration emit.

@typescript-bot
Copy link
Collaborator

This issue has been marked as "Declined" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Declined The issue was declined as something which matches the TypeScript vision Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants