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

Utility types to extract parts of Get #38

Open
jrmdayn opened this issue Sep 25, 2023 · 0 comments
Open

Utility types to extract parts of Get #38

jrmdayn opened this issue Sep 25, 2023 · 0 comments

Comments

@jrmdayn
Copy link

jrmdayn commented Sep 25, 2023

Sorry for the title which is quite obscure.. Let me explain what I am looking for, it will be more clear.

For a given data object:

const data = {
  foo: 42,
  bar: false
}

How can I type a getter function that given a path return the value at path?

const myFunction = (path: A):B => pipe(data,get(path))

myFunction('foo') // OK, =42
myFunction('bar') // OK, =false
myFunction('baz') // type error

Looking for what to put in type A and type B above. Is there some utility types I could use to achieve this?

Thanks 🙏

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