Skip to content
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

Extract common type fields into one new type #727

Open
ArinCantCode opened this issue Oct 12, 2022 · 1 comment
Open

Extract common type fields into one new type #727

ArinCantCode opened this issue Oct 12, 2022 · 1 comment
Labels
✨ Feature New refactoring or feature

Comments

@ArinCantCode
Copy link

Is this request related to a problem? Please describe.

I found myself having to extract common types into one base type, but because i have like 10 types in which not every field is in common it makes it very unpleasant to have to manually check if this field exists on every type.

  export interface Type1 {
    id: string;
    timestamp : number;
    block :number;
    platform : string;
    index :number;
    ...uncommon types
  }
  export interface Type2 {
    id: string;
    timestamp : number;
    block :number;
    platform : string;
    index :number;
    ...uncommon types
  }
  export interface Type3 {
    id: string;
    timestamp : number;
    block :number;
    platform : string;
    index :number;
    ...uncommon types
  }

ofc in reality this doesn't look so nice, fields are mixed together, file is long etc.

Describe the solution you'd like

Select all the types/interfaces and extract fields they have into new type/interface above or below it. Basic version of this feature could only extract from simple types that do not use & or extends

@ArinCantCode ArinCantCode added the ✨ Feature New refactoring or feature label Oct 12, 2022
@nicoespeon
Copy link
Owner

I like this suggestion @ArinCantCode. We could indeed detect similar patterns and suggest extracting the common parts together like we do when you extract all occurrences of a variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature New refactoring or feature
Projects
None yet
Development

No branches or pull requests

2 participants