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

Add new type: Flip<T>, FlipOptional<T>, Invert<T> or InvertOptional<T> (I'm not sure of the name) #130

Open
branchard opened this issue Dec 23, 2019 · 0 comments

Comments

@branchard
Copy link

Is your feature request related to a real problem or use-case?

This type can be usefull to reverse required and optional properties of an object.
Related question: https://stackoverflow.com/questions/57593022/reverse-required-and-optional-properties.

Describe a solution including usage in code example

Solution:

import { RequiredKeys, OptionalKeys } from 'utility-types';
export declare type Flip<T> = Partial<Pick<T, RequiredKeys<T>>> & Required<Pick<T, OptionalKeys<T>>>;

Usage:

import { Flip } from 'utility-types';

type MyObject = {
  a: number
  b?: number
  c?: number
};

type MyFlippedObject = Flip<MyObject>;
// Should be
// type MyObject = {
//  a?: number
//  b: number
//  c: number
// };

Who does this impact? Who is this for?

TypeScript users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant