With disallowSuperfluousProperties on, the following code results in wrong typecheck:
type Foo = {
quux: string;
};
type BarIntersection = {
foo: Foo;
} & {
bar: string;
};
type BarNotIntersection = {
foo: Foo;
bar: string;
};
const document = {
bar: 'bar',
foo: {
quux: 'quux',
super: 'fluous'
}
};
The super: 'fluous' property does not get caught with is<BarIntersection>, but is<Foo> and is<BarNotIntersection> both catch it. This is because typescript-is disables disallowSuperflousProperties when encountering an intersection (and for a good reason), but never restores it. I have written a test case and a quick-and-dirty fix, I will post a PR soon.
NOTE: This is just minimal reproduction, obviously the intersection is not needed in this example.
With
disallowSuperfluousProperties
on, the following code results in wrong typecheck:The
super: 'fluous'
property does not get caught withis<BarIntersection>
, butis<Foo>
andis<BarNotIntersection>
both catch it. This is becausetypescript-is
disablesdisallowSuperflousProperties
when encountering an intersection (and for a good reason), but never restores it. I have written a test case and a quick-and-dirty fix, I will post a PR soon.NOTE: This is just minimal reproduction, obviously the intersection is not needed in this example.