# Bug Report <!-- Please fill in each section completely. Thank you! --> ### π Search Terms <!-- What search terms did you use when trying to find an existing bug report? List them here so people in the future can find this one more easily. --> ### π Version & Regression Information <!-- When did you start seeing this bug occur? "Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs If possible, please try testing the nightly version of TS to see if it's already been fixed. For npm: `typescript@next` This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly Note: The TypeScript Playground can be used to try older versions of TypeScript. Please keep and fill in the line that best applies: --> - This is the behavior in every version I tried, and some behavior changed between versions 4.5.5 and 4.6.2 ### β― Playground Link <!-- A link to a TypeScript Playground "Share" link which shows this behavior The TypeScript Workbench can be used for more complex setups, try https://www.typescriptlang.org/dev/bug-workbench/ As a last resort, you can link to a repo, but these will be slower for us to investigate. --> [Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.6.2#code/C4TwDgpgBAqgjFAvFA3gWAFBW1AZge3wC4oAKAQwCcBzEgIgPzoEokA+KAN3wEsATANyYcUAEZUSFGvXGUW7Lr0GYAvpkyhIsAExJUUANoBpKDwB2UAOSNLUAD5XZlgLqSqtKEdaIO3flDUMAHognAA9AH51DE1oABUIAGdgPXgoCAAPYAgzPkSdKAiCzOzc-LSi4EoAV2gSXHIAG0S6vCaWoWDQ7EjMEKgAdwALHgBjIdNcsfJs-OAhmdgEHjmh6ETyAFtocnLtaNxqs1HgHnwLXDM4AB449KycvKsbe0cqSzZSUdESFGNJqBxVxLYzOFQGIEAGig7hIcWYJD8fFQwhw3yk1GYAig-VG+EolAgJ3SBPxqgORxOZwuZm0t3upSe1kItgclicn2+v3+5kBwJg2lB4KhMOkgIRin86CwaNEGKxONCiSG+GqjWREFJlDE1RSeM2YB4jSSADpyRhMIdjqdzngzABmeklR75Zn4VlvSgfL4-VA8ixAtxirwKJHC5zQ2HixFKFEy7Do9wK-rK1XqkmUfE6vX4A1G03my2Um00gAsToeZWeLNe7PenN9d2dVaOAGszPgBhYihi4d5fLGSGYIJxNZGxfCY1LUQm5Unsbj8YTiZrM5RVEA) ### π» Code ```ts // Literal version type U1 = { foo: (arg: "foo") => void; bar: (arg: "bar") => void; } // Mapped type version type U2 = { [K in 'foo' | 'bar']: (arg: K) => void } // ^? type U2 = { foo: (arg: "foo") => void; bar: (arg: "bar") => void; } type Is_U2_equivalent_to_U1 = U1 extends U2 ? U2 extends U1 ? true : false : false; // ^? type Is_U2_equivalent_to_U1 = true function fn1<T extends 'foo' | 'bar'>(cb: {[K in T]: U1[K]}[T], arg: T): void { cb(arg); // correct error } function fn2<T extends 'foo' | 'bar'>(cb: {[K in T]: U2[K]}[T], arg: T): void { cb(arg); // // correct error before 4.6, compiles after 4.6 } function fn3<T extends 'foo' | 'bar'>(cb: {[K in T]: (arg: K) => void}[T], arg: T): void { cb(arg); // should error but compiles } function fn4<T extends 'foo' | 'bar'>(cb: T extends unknown ? (arg: T) => void : never, arg: T): void { cb(arg); // correct error } ``` ### π Actual behavior In 4.5.5, `fn3` doesn't report an error. In 4.6.2, `fn2` and `fn3` doesn't report an error. I'm not sure but this maybe cause by https://github.com/microsoft/TypeScript/pull/47109 or https://github.com/microsoft/TypeScript/pull/47370 ? ### π Expected behavior Error reported in `fn1` and `fn4` should also be reported in `fn2` and `fn3`, because: - Provided that `U1` is equivalent to `U2`, it is inconsistent where `fn1` reports error but `fn2` does not. - The pattern `{[K in T]: G<K>}[T]` has a distributive behavior over `T`, so I expect it behave the same as the conditional type form `T extends unknown ? G<T> : never`, which reports error correctly as `fn4` shows. - An unsound call for `fn3`: `fn3<'foo' | 'bar'>((x: 'foo') => assert(x === 'foo'), 'bar')`