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

New refactoring (TS): Convert Omit<T> to Pick<T> and vice versa #769

Open
automatensalat opened this issue Dec 1, 2022 · 1 comment
Open
Labels
✨ Feature New refactoring or feature

Comments

@automatensalat
Copy link
Contributor

Is this request related to a problem? Please describe.

In Typescript there's a way to declare a type as a subset of another types properties, using Pick and Omit. Pick explicitly includes the properties of the source type while Omit excludes them and includes the others that were not specified.

type MyType = {
  a: number;
  b: number;
  c: number;
}

// the refactoring would convert between those two representations:
type OnlyAB1 = Pick<MyType, "a" | "b">; 
type OnlyAB2 = Omit<MyType, "c">;

Sometimes over time it turns out that a type definition using Pick would be better written using Omit, or the other way around.

Describe the solution you'd like

I'd like to have a refactoring that works on the TS level which converts one declaration to the other. E.g. if a type is declared using Pick and I execute the new Convert to Omit<> refactoring, it would analyze the source type, find out which properties were implicitly excluded using the previous Pick notation and make that explicit with the Omit notation.

@automatensalat automatensalat added the ✨ Feature New refactoring or feature label Dec 1, 2022
@nicoespeon
Copy link
Owner

Love the idea!

I think we still struggle to determine types that are imported (at least, we can't do that in Action Providers, too heavy). But it would work just fine for a locally defined type I think.

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