这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@Methrat0n
Copy link

@Methrat0n Methrat0n commented Jan 22, 2021

🎁 Pull Request

  • Used a clear / meaningful title for this pull request
  • Tested the changes in your own code (on your projects)
  • Added / Edited tests to reflect changes (tst folder)
  • Have read the Contributing part of the Readme
  • Passed npm test

Fixes

There is no issue with this as the contributing section does not ask to create one first.

Why have you made changes?

I used ts-toolbet to create this type and use it in my library ts-match.
I think it can be of use to others and want to give back to this project which helps a lot in my work.

What changes have you made?

  • Add Members.ts file in the Object directory
  • Add export of the Members type in the Object/_api.ts

What tests have you updated?

  • Add test for Members

Is there any breaking changes?

  • Yes, I changed the public API & documented it
  • Yes, I changed existing tests
  • No, I added to the public API & documented it
  • No, I added to the existing tests
  • I don't know

Anything else worth mentioning?

I commented one test which was failing and intends to create an issue about it.
I will gladly uncomment it if you prefer.

@Methrat0n Methrat0n requested a review from millsp as a code owner January 22, 2021 10:42
@Methrat0n Methrat0n changed the title Add Object/Members type to exctract the list of member types of any object Add Object/Members type to extract the list of member types of any object Jan 22, 2021
@millsp millsp closed this Jan 29, 2021
@millsp
Copy link
Owner

millsp commented Jan 29, 2021

Hey @Methrat0n, thanks for the proposition :)

I will not merge this, but thanks for your nice intentions. I appreciate.

We can re-write this like this:

type equivalent = U.TupleOf<U.UnionOf<YOUR OBJECT>>

@Methrat0n
Copy link
Author

I respect your choice, but I want to point out that your solution is not equivalent: you lose the types that are present multiple times. My second example with 2 number would not give the same result as yours.

@millsp
Copy link
Owner

millsp commented Jan 29, 2021

Does this work four you?

type Members<O extends object> =
    U.ListOf<keyof O> extends infer LK
    ? {[K in keyof LK]: O.At<O, LK[K] & keyof O>}
    : never

type test0 = Members<{a: 1, b: 2, c: {a: 1}}>

@Methrat0n
Copy link
Author

Yes, it does and thank's for the better implementation. That way of iterating over an array is really neet.

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

Successfully merging this pull request may close these issues.

2 participants