Repository: TypeScript
Issue: `NonNullable` is not resolved for a mapped type in a contextual parameter type from instantiated type alias
Labels: Bug

# Bug Report

### 🔎 Search Terms

NonNullable, Omit, mapped type, contextual type

### 🕗 Version & Regression Information

- This changed between versions 4.7 and 4.8

### ⏯ Playground Link

[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.9.0-dev.20221025#code/C4TwDgpgBA4hDOwCuAnCBpCIoF4oCIATFAQwHN8BuAKFEigBFSyBlYE4aPAbygFsA9gDcIfCADtgALigBtcUj4AjCCgA0UBctUBdSlAC+NagEtJqgGYkAxtDYdo3alCjFyAfhlNy9zjQPUtOB2ABYkaIRwiKgQvlxQTi5uZGRmZJ5QSgICADYQJOL+xnTQAGJIOTlRyGhxADyY2BAAHpzihPCwCDUYWAB8uFAsYRHVMXFQAGTOUAByAuKzFTkkSnl1cbKNOn3FwVAAEgWEeSgNWFAtbR1d0WiNA3gAFDOIDjIA8nwmwHXllWNauxOOcQH0NPgICJJPg+tQAJS4AZCAQmQjGawLRBQADuAhQAGtOs83pxPt9fv8qt1xsCIHUiMxYRCoRJgLDETgBokoKSIDQXAB6QVQAB67hmMxKQzpjWJUAJWAEFigJWVvLpAqgwpcYolLkx4nguQgADocgIyE8+abBCIxJJ4UVAobsYQBAhJAB1fEEmRHdqnBnJWGDa10znc16amY68WBFzSuJywaKkDqtUqvlanUueMGrEm82W8MOW3CURsp3UIzUIA)
[Original repro case](https://www.typescriptlang.org/play?target=99&ts=4.8.4#code/C4TwDgpgBA4hDOwCuAnCBpCIoF4oHIATFAQwHN8oAfAsASwDsBjAC3wCh3RIoBhAewC2g-gwDKwEsGh4A3lBEA3CIIgNgALigBtBkkEAjCCgA0UPYeMBdKAF8u4aABFSZCVJl8hI8ZOlQAMih5QjpEEmYILV19I1NzWOs7Bx4ABUZWd388AWFRLOgg+QiyABsohMsUZPZGaRQAMxImaALg9igoYnIAfi0XcgKOqHpmFj6odLGh+xToAFFldQAVR3hcds7usi1U-jrjRbVgaihl-iRWI-VTgFkL+Ahrk5pMEAN+EhRCZ+GAdxYEAgpS0AHVAcDfp14EwUPxSiCoABVACSUIU-GUu326kOS2AwxYmOM2IOKHRo1YpNx5Pxp3OlxYz1O4KBpV+syg3FaLC+EEIcEQqAgbTkw22ZEYZAmH3hEAi7Fm3KgADEkAjBcg0AUADxvKAQAAe0gYhHWmuFbwAfBsxLy0AKEFqRX5ClAAHKid3q0okAzlHUFbRvKxWzjKgASEUI5RQeqwBuNajNsCdlqwNrwAAphuFpFoAPKCOjAHVqjVp7Wu+MgK1mfAQfH4MMASlwNoi2Boin2hE4TFEiCgf34KAA1uts3mKkWS2WfRaqx4dURXM3643js22zgbbJhgOGPA5QA6Ur8MhZ6cnpQqY4txX9wcnQj8BDqUGjsdaKOm2Mr7Zmw2K9XR3PcD0HU9z0va9b1UdQH1sIA)

### 💻 Code

```ts repro
type GestureKey = "drag";
type DragState = { movement: [number, number]; };

interface State {
  drag?: DragState;
}

type SharedGestureState = {
  dragging?: boolean;
};

type FullGestureState<Key extends GestureKey> = SharedGestureState &
  NonNullable<State[Key]>;

type Handler<Key extends GestureKey> = (
  state: Omit<FullGestureState<Key>, "event">
) => void;

const works = (state: Omit<FullGestureState<"drag">, "event">) => {
  state;
  // ^? (parameter) state: Omit<SharedGestureState & DragState, "event">
  
  type StateKeys = keyof typeof state;
  //   ^? type StateKeys = "dragging" | "movement"
  console.log(state.movement);
};

const doesntWork: Handler<"drag"> = (state) => {
  state; (parameter) state: Omit<SharedGestureState & DragState, "event">
  // ^? (parameter) state: Omit<SharedGestureState & DragState, "event">

  type StateKeys = keyof typeof state;
  //   ^? type StateKeys = "dragging"
  console.log(state.movement); // Property 'movement' does not exist on type 'Omit<SharedGestureState & DragState, "event">'.(2339)
};

```

### 🙁 Actual behavior

We can observe a type error in the `doesntWork` function and the `keyof` reporting incorrect result there for the given parameter type.

### 🙂 Expected behavior

There should be no error as the type for the `state` parameter in both functions is the same.

cc @ahejlsberg