Skip to content

requireStateProperty

requireStateProperty<S, K>(state, key, message?): asserts state is S & Record<K, NonNullable<S[K]>>

Defined in: src/util/types.ts:98

Runtime assertion that a state property exists. Throws an error if the property is missing.

S extends Record<string, any>

K extends string | number | symbol

S

K

string

asserts state is S & Record<K, NonNullable<S[K]>>

requireStateProperty(ctx.state, 'userId');
// Now TypeScript knows ctx.state.userId exists
const id = ctx.state.userId;