Type alias KosContainerAwareWithProp<T, P>

KosContainerAwareWithProp<T, P>: KosContainerAwareBase<T> & {
    [K in P]: IKosModelContainer<T>
}

Interface for models using

Type Parameters

  • T extends IKosDataModel = IKosDataModel

    The type of models contained in the container

  • P extends string = "container"

    The custom property name for the container (string literal type)

Kos Container Aware

decorator with a custom container property name.

Use this interface when you specify a custom containerProperty in the decorator options to get proper type safety for the custom property name.

Example

// Specify the custom property name "devices" in both the interface and decorator
interface DeviceManagerImpl extends KosContainerAwareWithProp<DeviceModel, "devices"> {}

@kosModel("device-manager")
@kosContainerAware<DeviceModel>({ containerProperty: "devices" })
class DeviceManagerImpl implements IKosDataModel {
constructor(modelId: string, options: ContainerOptions, context: KosCreationContext) {
this.id = modelId;
}

addDevice(device: DeviceModel): void {
// Access container via custom property name
this.devices.addModel(device);
}

getDeviceCount(): number {
// The 'data' property is still available
return this.data.length;
}
}

Example

// Custom property for user management
interface UserManagerImpl extends KosContainerAwareWithProp<UserModel, "users"> {}

@kosContainerAware<UserModel>({
containerProperty: "users",
containerOptions: {
indexMap: {
byRole: "role"
}
}
})
class UserManagerImpl implements IKosDataModel {
getUsersByRole(role: string): UserModel[] {
// Access via this.users instead of this.container
return this.users.getIndexByKey("byRole", role);
}
}