π Search Terms
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=5.6.2#code/CYUwxgNghgTiAEYD2A7AzgF3gMwFzwB4AFAPgAoAoeHFfMgBxiXrXyIEp4BeE+ANyQBLYABoq8QSkEYA-GzGce8IgG4KFSRhAxsUMAiJMW8AN7i4AR3yYYkgOZrqzWdYy2UDigF91ydFkZmNG4cSmoGNiM0RV4AclixahN4S3wAIjT4LwU1CkCWADpnCgB6EvgAURgmGAkUeAAVAGV4AFYCgDYReBQkLEl4EFgIQW1+bTRBVDQKIA
π» 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 π