Skip to content

Can Path<T> extend string? #14

@acurrieclark

Description

@acurrieclark

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions