0.1.1 • Published 9 months ago

typed-json-parse v0.1.1

Weekly downloads
-
License
GLWTPL
Repository
github
Last release
9 months ago

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.

So, why?

I was bored.

0.1.1

9 months ago

0.1.0

9 months ago