From 425a2c086d2eefdca20b18f31cf281dd4060730e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 19:41:14 +0000 Subject: [PATCH] Initial investigation of exhaustiveness checking issue Co-authored-by: RyanCavanaugh <6685088+RyanCavanaugh@users.noreply.github.com> --- test-issue.ts | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 test-issue.ts diff --git a/test-issue.ts b/test-issue.ts new file mode 100644 index 00000000000..64ffd9c8012 --- /dev/null +++ b/test-issue.ts @@ -0,0 +1,49 @@ +// Test the issue: Exhaustiveness checking against an enum with 1 member + +enum ActionTypes { + INCREMENT = 'INCREMENT', +} + +interface IIncrement { + payload: {}; + type: ActionTypes.INCREMENT; +} + +type AnyStringExcept = { [P in T]: never; }; + +type ValidAction = IIncrement; +type UnhandledAction = { type: AnyStringExcept; }; +type PossibleAction = ValidAction | UnhandledAction; + +function isUnhandled(x: PossibleAction): x is UnhandledAction { + return !(x.type in ActionTypes); +} + +type CounterState = number; +const initialState: CounterState = 0; + +function receiveAction(state = initialState, action: PossibleAction) { + if (isUnhandled(action)) { + return state; + } + + // typeof action === ValidAction + switch (action.type) { + case ActionTypes.INCREMENT: + return state + 1; + } + + // This should not error - all cases are handled + const n: never = action; + return state; +} + +// Simpler test case from RyanCavanaugh's comment +function fn(obj: { name: "bob" }) { + if (obj.name == "bob") { + // bob case + } else { + // Should not be an error + const n: never = obj; + } +}