Skip to content

getStateProperty

getStateProperty<S, K, D>(state, key, defaultValue?): D | S[K]

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

Type-safe state getter with optional default value.

S extends Record<string, any>

K extends string | number | symbol

D = undefined

S

K

D

D | S[K]

const userId = getStateProperty(ctx.state, 'userId', 'anonymous');