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

Passing a generic to Path does not work #10

Open
dbrxnds opened this issue Mar 1, 2023 · 1 comment
Open

Passing a generic to Path does not work #10

dbrxnds opened this issue Mar 1, 2023 · 1 comment

Comments

@dbrxnds
Copy link

dbrxnds commented Mar 1, 2023

Hi,

It seems that passing a generic which extends something does not correctly resolve at least the extended options:

Reproduction: https://tsplay.dev/NaEx9N

@ErikCoup
Copy link

ErikCoup commented Mar 9, 2023

A related example:

import { getByPath, Path } from 'dot-path-value';

const users = { name: 'Someone', pets: [{ cats: 2 }] };

function getValue<T extends Record<string, any>>(obj: T, path: Path<T>) {
  return getByPath(obj, path);
}

// Here, the type of `cats` is the union of all field types, i.e.:
// `string | number | { cats: number; } | { cats: number; }[]`
const cats = getValue(users, 'pets.0.cats');

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

2 participants