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

Idea for type to generically describe a single key-value object from a multi key value object #11

Open
renewooller opened this issue Mar 1, 2018 · 4 comments

Comments

@renewooller
Copy link

Given an object structure like:

interface A {
    AA : string
    BB : number
}

derive:

type C = {AA : string } | { BB : number}

This is how:

type Unionify<T> = {[K in keyof T]: Pick<T, K>}[keyof T];

type C = Unionify<A>

I'm not sure if it should be called Unionify or OneOf. Any idea on naming or other feedback appreciated.

@pelotom
Copy link
Owner

pelotom commented Mar 2, 2018

@renewooller
Copy link
Author

Maybe OneOf is better then just to more clearly separate it from Unionize?

@pelotom
Copy link
Owner

pelotom commented Mar 2, 2018

Isn't it the same thing as Unionize? Why do we want to separate it?

@renewooller
Copy link
Author

renewooller commented Mar 2, 2018

Unionize looks like it also does Key(Tag)Valueification in the same step. That is, rather than {AA : string } | { BB : number} it does {tag : "AA", value : string } | { tag : "BB", value : number}. I may be reading it wrong though.

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

2 participants