[Feature request] Improve TypeScript support
Evertt opened this issue · 0 comments
Evertt commented
I know that this library already has basic typescript support, but it could be better.
In two ways:
- Right now, both
stringify
anduneval
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. - 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. :-)