typed-json-parse
v0.1.1
Published
A JSON parser built in TS Types to statically type JSON.parse() output, for reasons
Downloads
144
Maintainers
Readme
Typed JSON Parse
Summary
This package overrides the default JSON.parse()
types with a JSON parser built in TypeScript types, meaning if you put a valid string literal in, you will get the actual type it represents or a somewhat useful error message.
import "typed-json-parse"
const value = JSON.parse('{ "Hello": "NPM!", "foo": [true, 123] }')
// With the actual type of value being:
const value: {
Hello: string,
foo: (boolean | number)[]
}
But that's useless
Correct. Since you have the literal string, just use the contents in JS/TS. As a tiny bonus, any non-literal string produces unknown
instead of any
.