gristlabs / ts-interface-checker

Runtime library to validate data against TypeScript interfaces.
Apache License 2.0
323 stars 18 forks source link

Strict check not working correctly for extended interfaces #35

Closed mdesousa closed 3 years ago

mdesousa commented 3 years ago

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
  });
});
dsagal commented 3 years ago

This seems a genuine bug, thanks for reporting!

RomRider commented 3 years ago

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

RomRider commented 3 years ago

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

dsagal commented 3 years ago

Will do this weekend!

On Fri, Feb 19, 2021 at 11:30 AM Jérôme W. notifications@github.com wrote:

Thanks for the fix @dsagal https://github.com/dsagal! Any plan to release a version with those fixes included? 😊

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/gristlabs/ts-interface-checker/issues/35#issuecomment-782185364, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIKMRYEVK4IH6FY5IWAJLLS72GZNANCNFSM4V7LSQJA .