gcanti / io-ts-types

A collection of codecs and combinators for use with io-ts
https://gcanti.github.io/io-ts-types/
MIT License
311 stars 40 forks source link

Export `Json` from `JsonFromString` #156

Closed merisbahti closed 3 years ago

merisbahti commented 3 years ago

🚀 Feature request

Current Behavior

The Json codec is used in the definition of JsonFromString, but it's not exported, and it makes it hard to depend on JSONFromString because it's useful to assert for example that "I care that this key exists, but the value of that key is Json too` https://github.com/gcanti/io-ts-types/blob/master/src/JsonFromString.ts#L27

Desired Behavior

export that line.

gcanti commented 3 years ago

I care that this key exists, but the value of that key is Json too

Would you be willing to provide an example?

merisbahti commented 3 years ago

I have a few examples, so for example we're able to get the "A"-type using typeof JsonFromString._A which is great and all, but if we're asserting for example:

const myApiReturnsThis = JsonFromString.pipe(type({
  myKey: evenMoreJson
}))

All I wanna verify is that the server returns an object with the type {myKey: typeof JsonFromString._A}. Since we're only able to get the type and not codec, we can't do this. making the JsonFromString-codec a bit less useful IMO.

(More examples coming later if you're not convinced)

gcanti commented 3 years ago

@merisbahti thanks (I'm convinced)

we're able to get the "A"-type using typeof JsonFromString._A

Btw there's an official util for this (TypeOf), see TypeScript integration

merisbahti commented 3 years ago

you are the best 🚀