StatePropertyAccessor interface

Interface for accessing a property in state storage with type safety.

Remarks

This interface defines standard methods for working with persisted state properties, allowing property access with strong typing to reduce errors when working with complex state objects.

Methods

delete(TurnContext)

Deletes the persisted property from its backing storage object.

Example

await myProperty.delete(context);
get(TurnContext)

Reads a persisted property from its backing storage object.

Example

const value = await myProperty.get(context, { count: 0 });
get(TurnContext, T)

Reads a persisted property from its backing storage object.

set(TurnContext, T)

Assigns a new value to the properties backing storage object.

Example

await myProperty.set(context, value);

Method Details

delete(TurnContext)

Deletes the persisted property from its backing storage object.

Example

await myProperty.delete(context);
function delete(context: TurnContext): Promise

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

Returns

Promise

Remarks

The properties backing storage object SHOULD be loaded into memory on first access.

get(TurnContext)

Reads a persisted property from its backing storage object.

Example

const value = await myProperty.get(context, { count: 0 });
function get(context: TurnContext): Promise

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

Returns

Promise

Remarks

The properties backing storage object SHOULD be loaded into memory on first access.

If the property does not currently exist on the storage object and a defaultValue has been specified, a clone of the defaultValue SHOULD be copied to the storage object. If a defaultValue has not been specified then a value of undefined SHOULD be returned.

get(TurnContext, T)

Reads a persisted property from its backing storage object.

function get(context: TurnContext, defaultValue: T): Promise

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

defaultValue

T

(Optional) default value to copy to the backing storage object if the property isn't found.

Returns

Promise

set(TurnContext, T)

Assigns a new value to the properties backing storage object.

Example

await myProperty.set(context, value);
function set(context: TurnContext, value: T): Promise

Parameters

context
TurnContext

Context for the current turn of conversation with the user.

value

T

Value to assign.

Returns

Promise

Remarks

The properties backing storage object SHOULD be loaded into memory on first access.

Depending on the state systems implementation, an additional step may be required to persist the actual changes to disk.