Repository: TypeScript
Issue: Inference lost on params of key-value function map
Labels: Bug

# 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.
-->

Inference Lost, function params map

### 🕗 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 a crash
- This changed between versions ______ and _______
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
- I was unable to test this on prior versions because _______

### ⏯ 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?#code/KYDwDg9gTgLgBMAdgVwLZwCoCUCCA5AZQEkMiB5QuAbwCg564c4BeOAcgEM2AaOhgIRbsARjz4BfGjVCRYCFOgIYcGAKIFqfehVVC2ERMDENMAdTJ6YAdwhjJUmdHgBjADYcAzh7gEYHGMBkhmTCAFbAzvC0JgAmEAQQqMAwABYAlogA5gAUAJRUkpKOcm6e3r7+wBg2IeGRmrHxicnpWXkFNPbF8DAAnmDAPn4BHhgQtREw3qzRDADaSirqAHQ6ALoAXEOVQYFhkwDcWnALymoEyxjmm9sB1eP7kUfiR9LgTnDOBh7wOAAyfzIplUABEAPqLc5ggBiWDIAFkwdh8MRSBQhLN6HNkYQSORCMscDdTksLjpuD4zisrmQ1rwTNjcLi0QT+MTISt1vS4OI4J5Pt8YK8aAAzZCISJpAxwEYwAA80KgiQwUA4iA8aRgUsQCBAAUQMW8ONR+IIAD5sscTDBVerNdqtorlbaNVqDNyTPRIF40sI0q5NcAPFtMZ6GU7UBUAnAMjL+sAICLGACgaCIVSCDC4YjjXiKHMIyq1a7tWs5gphMAoGsbpaw-W4D9Klso0GxhNIh4C0rI8NgHSrfXciwzXzEL0jg36OIPXBh7RjvYAPRLzD9DKZOCroiIAKuAMeJCHmPeRAQeA2KAAaw3cCkK7geAMg0TMpSwHQl6vNFl2VzLIuHAKVmB8m2jNJvDVXo4GEZB4E1RsUggZBXBiGDBlbXYOxgY5ny2MDBmYUcqDgKBkmQKAdQInluVAvsTzHaDYPg+APCQlC0MrW4qhqR4cOtGx8PoojqFI8jKMbejClye9VyCVxoK-bxUkGEU0igH44GfH8gxgP8mRNChAOAvgH1bBjMOCPiYLgyTKhlGwGNQCCNSyCkzygVAOFcBAoCVKBcMMIT7JEkiyJgCiqL7ZY4gSJJUg3PIaM6GSaAfDB3zIhiDAUrTDDgb0NT9AM+hsli4DiINEDYC9oG-X9-1NZZ+BM+g6PsiDGLKmNWPY1D0O4rC+MC4BgujUKxIiiTqJnFKgA)

### 💻 Code

<!-- Please post the relevant code sample here as well-->
```ts
export enum TRANSITIONS {
    A = 'a',
    B = 'b',
  }

export enum STATES {
    ONE = 'one',
    TWO = 'two',
}


export class StateOneObject {
    doSomething(){}
}
export class StateTwoObject {
    doSomething(){}
}

export type StatesToObjects = {
    [STATES.ONE]: StateOneObject;
    [STATES.TWO]: StateTwoObject;
};

export const ALLOWED_STATES_FROM_TRANSITION = {
    [TRANSITIONS.A]: [STATES.ONE, STATES.TWO],
    [TRANSITIONS.B]: [STATES.ONE],
  } as const;


function test<FromTransition extends TRANSITIONS>(
        transition: FromTransition,
        possibilites: {
            [FromState in typeof ALLOWED_STATES_FROM_TRANSITION[FromTransition][number]]: (
              state: StatesToObjects[FromState],
            ) => any;
          },
    ) {

    }

// Typing / Intellisense is not working 

// None of them work
test(TRANSITIONS.A, {
  // state is any but it should be StateOneObject
    one: state => { return state },
  // state is any but it should be StateTwoObject
    two: state => { return state }
})

// Only works the first one
test(TRANSITIONS.A, {
  // State is StateOneObject but state two is missing, normal error
    one: state => { return state.doSomething() },
})

// There is only one possibility but it doesn't work
test(TRANSITIONS.B, {
  // state is any but it should be StateOneObject
    one: state => { return state },
})
```

### 🙁 Actual behavior

<!-- What happened, and why it was wrong -->
Function state param shows error when adding the second state to the object. Please do hover over the state param.

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->
The state should be from the expected type