gristlabs/ts-interface-checker

Strict check not working correctly for extended interfaces

mdesousa opened this issue · 4 comments

If you perform a strict check on an extended interface you will get an incorrect error about extraneous properties defined in the child interface.
See below sample code that illustrates the problem... the second test fails with an error: value.childProp is extraneous

import { createCheckers } from "ts-interface-checker";
import checkerTI from "./checker.test-ti";
const checkers = createCheckers(checkerTI);

interface IParent {
  parentProp: string;
}

interface IChild extends IParent {
  childProp: string;
}

describe("checker test", () => {
  const value: IChild = {
    parentProp: "parent value",
    childProp: "child value",
  };

  it("check a value", async () => {
    checkers.IChild.check(value); // passes
  });

  it("strict check a value", async () => {
    checkers.IChild.strictCheck(value); // fails
  });
});

This seems a genuine bug, thanks for reporting!

Same issue here. Seems like the additional attributes are undefined while the checker is running.

Thanks for the fix @dsagal! Any plan to release a version with those fixes included? 😊