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.
Type Parameters
Section titled “Type Parameters”S extends Record<string, any>
K extends string | number | symbol
Parameters
Section titled “Parameters”S
K
message?
Section titled “message?”string
Returns
Section titled “Returns”asserts state is S & Record<K, NonNullable<S[K]>>
Example
Section titled “Example”requireStateProperty(ctx.state, 'userId');// Now TypeScript knows ctx.state.userId existsconst id = ctx.state.userId;