Using intersection types breaks type inference for function types
🔎 Search Terms
inference intersection function inference intersection
🕗 Version & Regression Information
- This changed between versions 3.3.3 and 3.5.1
⏯ Playground Link
https://www.typescriptlang.org/play/?ts=3.5.1#code/GYVwdgxgLglg9mABABwE52QHgCoBpEDSiApgB5TFgAmAzogNbECecwi2AfABQD6jTALkIBKIVxhhkIKEOzDEAXg7sA2gQC6iAN4BYAFCJEUABboA7ojDELAUVTpUXAEQA5OFEQwAtsgA2xL0oKKidhAG59AF99fVBIWAQUGGRiTABBfAAhbgkpGUQMxGAARjFc6SE0+SVETNFaiL046HgkZGTUwsz8AGEcyQqC-BKygfyqxWVuooAmUbyhOsnEHvqexuaEto6uADp9ngBDVABzGiFwejA4MzAVdXrL69vtfUMTc0trRDsHZzcPN4-AEgsQQuEojE9FAmClEAARYgQOCoQ7BYo4fAAVWUCleBkQXGOJ1k9SxjUMVBAXi8gkQNCgqAkJ0akUa+hhcMRyNRwRmmMQOMU+MMRNOpKE5KiiAAZCLEFSaXSGUywCyouymuAWokvIdkBi8ILuDwIIdfL4AEaHCD0YBgMQAN3NIGIpOWWPq3JRaLBhvu2Puyl0BI+Ny+tnsKP+7k8Pn8gTAwVCrKhm1aiD1yH5RpxvDNFuttvtTpdbvY1WUnqE3t5YJzAcFQflYYsVkjf1csaBCdB4NTen07RSXDe2k8YCsqCEKmK+Bm+AAzJpIrgx2gMM4JFPQmuCVnilwuKRK4hSIgAFSIYoABmEe4hg70w+Io4JWgnU5nc8QC8Qy8QVd13QZAt0nYhUF3McsxmI8T2Wc8r1ve99EfIA
💻 Code
function prop<T, K extends keyof T>(_key: K): (input: T) => T[K] {
throw new Error("Not implemented");
}
function pipe<A, B>(input: A, f1: (input: A) => B): B;
function pipe<A, B, C>(input: A, f1: (input: A) => B, f2: (input: B) => C): C;
function pipe(..._args: unknown[]): unknown {
throw new Error("Not implemented");
}
type Decorated1<T, U> = {
(arg: T): U;
dummy: string;
};
type Decorated2<T, U> = {
(arg: T): U;
} & {
dummy: string;
};
function map1<T, U>(_callbackfn: (value: T) => U): Decorated1<T[], U[]> {
throw new Error("Not implemented");
}
function map2<T, U>(_callbackfn: (value: T) => U): Decorated2<T[], U[]> {
throw new Error("Not implemented");
}
pipe(
{ inner: [1, 2, 3] },
prop("inner"),
map1((x) => x * 10),
);
pipe(
{ inner: [1, 2, 3] },
prop("inner"),
map2((x) => x * 10),
);
🙁 Actual behavior
Type inference fails when using map2.
🙂 Expected behavior
Type inference succeeds for both map1 and map2.
Additional information about the issue
Using the & operator to add members to a function type breaks type inference, but using a single record type works as expected.
It feels like a duplicate of https://github.com/microsoft/TypeScript/issues/58833
This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.