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

Can Path<T> extend string? #14

Open
acurrieclark opened this issue Jun 7, 2023 · 0 comments
Open

Can Path<T> extend string? #14

acurrieclark opened this issue Jun 7, 2023 · 0 comments

Comments

@acurrieclark
Copy link
Contributor

I am using getByPath in a helper function and passing in a Path<T> as a parameter. The path is useful to me in another package, which takes an array rather than a "dotted" path. However, attempting path.split('.') throws up a Property 'split' does not exist on type 'Path<T>' typescript error.

function takesPathAsArray(path: string[]) {
  // does something fancy with the path
}

function helperFn<T>(obj: T, path: Path<T>) {
  const value = getByPath(obj, path);

  // error is here                       v v v v v v v v 
  const somethingElse = takesPathAsArray(path.split('.'));
}

I can of course cast path as a string there, but I was wondering if there was a way for the library to support it?

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