fix: retain cache key correlation in the reader type

The second index loses the cache-key correlation across the record union. Assert the identical indexed return type with the structural proof documented; emitted reader code is unchanged.
This commit is contained in:
Brennan Benson
2026-11-09 16:46:21 -08:00
parent 10673e2cdd
commit bf5ac9b84e
@@ -26,7 +26,8 @@ type ReferenceCache =
// Keep long-lived readers out of the read closures' store-snapshot scope.
function cacheEntryReader<K extends ReferenceCache>(cache: K, key: string) {
return <S extends Pick<AppState, K>>(state: S): S[K][string] | undefined => state[cache]?.[key]
// oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: both sides index the same cache K; TypeScript loses that correlation at the second index.
return (state: AppState) => state[cache]?.[key] as AppState[K][string] | undefined
}
function lookup<T>(