No interfaces
and type aliases
No runtime validation
elm
ts.data.json
Runtype
io-ts
etc...
JsonDecoder.string: Decoder<string>; JsonDecoder.number: Decoder<number>; JsonDecoder.boolean: Decoder<boolean>;
import { JsonDecoder } from 'ts.data.json';
interface Person {
name: string;
}
const personDecoder = JsonDecoder.object<Person>(
{ name: JsonDecoder.string },
'Person'
);
const invalidPerson = { name: 1 };
personDecoder
.decodePromise(invalidPerson)
.then(console.log)
.catch(console.error);
// <Person> decoder failed at key "name"
// with error: 1 is not a valid string
KAJETAN ŚWIĄTEK
kajetansw
dev-self-start