Closed
Description
π Search Terms
epc excess common properties weak type noinfer
π Version & Regression Information
- I was unable to test this on prior versions because
NoInfer
was introduced in 5.4
β― Playground Link
π» Code
declare function test1<T extends { x: string }>(
a: T,
b: NoInfer<T> | (() => NoInfer<T>),
): void;
test1({ x: "foo" }, { x: "bar" }); // an incorrect epc error
test1({ x: "foo" }, { x: "bar", y: 42 }); // epc error but on a wrong property
declare function test2<T extends { x: string }>(
a: T,
b: NoInfer<T> | NoInfer<() => T>,
): void;
test2({ x: "foo" }, { x: "bar" });
test2({ x: "foo" }, { x: "bar", y: 42 }); // should have an epc error
declare function test3<T extends { x: string }>(
a: T,
b: NoInfer<T | (() => T)>,
): void;
// those work fine
test3({ x: "foo" }, { x: "bar" });
test3({ x: "foo" }, { x: "bar", y: 42 });
declare const partialObj1: Partial<{ a: unknown; b: unknown }>;
declare const partialObj2: Partial<{ c: unknown; d: unknown }>;
declare const someObj1: { x: string };
declare function test4<T>(a: T, b: NoInfer<T> & { prop?: unknown }): void;
test4(partialObj1, someObj1); // should report no common props error
declare function test5<T1, T2>(
a: T1,
b: T2,
c: NoInfer<T1> & NoInfer<T2>,
): void;
test5(partialObj1, partialObj2, someObj1); // should report no common props error
declare function test6<T1, T2>(a: T1, b: T2, c: NoInfer<T1 & T2>): void;
test6(partialObj1, partialObj2, someObj1); // this one works ok
π Actual behavior
Excess property check doesn't work properly when union members are wrapped by NoInfer
individually. Similarly common properties check doesn't work properly with intersections when its members are wrapped by NoInfer
individually
π Expected behavior
I've annotated the playground with expected results where appropriate
Additional information about the issue
this open PR fixes it: #57673