Skip to content

hasStateProperty

hasStateProperty<S, K>(state, key): key is K & keyof S

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

Type guard to check if a state property exists and narrow its type.

S extends Record<string, any>

K extends string

S

K

key is K & keyof S

if (hasStateProperty(ctx, 'userId')) {
// ctx.state.userId is now typed as defined (not undefined)
console.log(ctx.state.userId);
}