Closed as not planned
Description
π Search Terms
- variance
π Version & Regression Information
- This changed in commit or PR Improve logic that chooses co- vs. contra-variant inferencesΒ #57909 (bisected via
every-ts
)
β― Playground Link
π» Code
declare const f: <P>(
fn: (props: P) => void,
init?: P,
) => P;
interface Props {
req: string;
opt?: string;
}
const props = f(
(p: Props) => '',
{ req: "" },
);
props.opt
// Error in TS 5.6, not in earlier versions
π Actual behavior
P
is inferred as {req: string}
, so accessing the optional property causes a TypeScript error.
π Expected behavior
P
should be inferred as Props
, as it is in TS 5.5 (and earlier). If you drop the init
parameter from the call to f
, then P
is also inferred to be Props
in TS 5.6.
Additional information about the issue
This seems related to #59764 but I'm not sure it's the same, so I figured I'd file an issue. I tried the same code on the playground for #59709 and it does not fix this issue.
cc @Andarist for whether TS 5.6 is right and I'm wrong π