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

[Proposal] Strongly typed Pick / Omit #42

Open
patarapolw opened this issue Jun 19, 2020 · 0 comments
Open

[Proposal] Strongly typed Pick / Omit #42

patarapolw opened this issue Jun 19, 2020 · 0 comments

Comments

@patarapolw
Copy link

patarapolw commented Jun 19, 2020

Actually, it is as simple as

import dotProp from 'dot-prop-immutable'

export function pick<T> (el: T, select: (string | number)[]): Partial<T> {
  let p = {} as Partial<T>

  select.map((k) => {
    p = dotProp.set(p, k, dotProp.get(el, k))
  })

  return p
}

export function omit<T> (el: T, deSelect: (string | number)[]): Partial<T> {
  let p = el as Partial<T>

  deSelect.map((k) => {
    p = dotProp.delete(el, k)
  })

  return p
}

However, I cannot make it strongly typed for select / deSelect that contains no dot...

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