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

[Feature request] Improve TypeScript support #47

Open
Evertt opened this issue Nov 2, 2022 · 0 comments
Open

[Feature request] Improve TypeScript support #47

Evertt opened this issue Nov 2, 2022 · 0 comments

Comments

@Evertt
Copy link

Evertt commented Nov 2, 2022

I know that this library already has basic typescript support, but it could be better.

In two ways:

  1. Right now, both stringify and uneval are typed as (value: any) => string. So you won't get a compiler warning if you're giving it an input that would throw an error, like an object with functions. It's possible to define the exact type that value is allowed to be and that would be nice to have.
  2. It would also be nice if you could do this:
interface User {
    name: string
}

const { user } = devalue.parse<{ user: User }>(data)

In situations where you're absolutely sure what data is gonna parse to. I'm aware that right now you can achieve the same by writing it like this:

interface User {
    name: string
}

const { user } = devalue.parse(data) as { user: User }

So this second point is less important than the first, but still it would be nice.

Edit

If you approve, but don't feel like implementing it any time soon, I could submit a PR. :-)

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