Notoriously Pedantic Magistrate

    io-ts-excess
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    io-ts-excess

    A type for io-ts library, which will fail on any additional properties.

    Thanks to @gcanti for the original code.

    Warning! Does not work from inside intersection!

    Usage

    import * as t from "io-ts";
    import excess from "io-ts-excess";
     
    const C = excess(
      t.type({
        a: t.string,
      }),
    );
     
    import { PathReporter } from "io-ts/lib/PathReporter";
     
    console.log(PathReporter.report(C.decode({ a: "a", b: 1 })));
    // [ 'Invalid value {"a":"a","b":1} supplied to : { a: string }, excess properties: ["b"]' ]

    TODO

    • Make it to work inside intersection. The following code does not work for now:
    const I = t.intersection([C, t.type({ b: t.number })])
     
    console.log(PathReporter.report(I.decode({ a: 'a', b: 1 })))
    // [ 'Invalid value {"a":"a","b":1} supplied to : { a: string }, excess properties: ["b"]' ]

    Install

    npm i io-ts-excess

    DownloadsWeekly Downloads

    7,696

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    3.72 kB

    Total Files

    4

    Last publish

    Collaborators

    • or-hai.levy