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
Original repro case
💻 Code
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
Bug Report
🔎 Search Terms
NonNullable, Omit, mapped type, contextual type
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
Original repro case
💻 Code
🙁 Actual behavior
We can observe a type error in the
doesntWorkfunction and thekeyofreporting incorrect result there for the given parameter type.🙂 Expected behavior
There should be no error as the type for the
stateparameter in both functions is the same.cc @ahejlsberg