feat: add generic type for property value

This commit is contained in:
Ilia Mashkov
2026-01-09 16:11:35 +03:00
parent 6f7e863b13
commit 1990860717
6 changed files with 52 additions and 25 deletions

View File

@@ -1,4 +1,4 @@
export interface Property {
export interface Property<TValue extends string> {
/**
* Property identifier
*/
@@ -7,13 +7,17 @@ export interface Property {
* Property name
*/
name: string;
/**
* Property value
*/
value: TValue;
/**
* Property selected state
*/
selected?: boolean;
}
export interface FilterModel {
export interface FilterModel<TValue extends string> {
/**
* Search query
*/
@@ -21,15 +25,15 @@ export interface FilterModel {
/**
* Properties
*/
properties: Property[];
properties: Property<TValue>[];
}
/**
* Create a filter store.
* @param initialState - Initial state of the filter store
*/
export function createFilter<T extends FilterModel>(
initialState: T,
export function createFilter<TValue extends string>(
initialState: FilterModel<TValue>,
) {
let properties = $state(
initialState.properties.map(p => ({

View File

@@ -22,6 +22,7 @@ describe('createFilter - Filter Logic', () => {
return Array.from({ length: count }, (_, i) => ({
id: `prop-${i}`,
name: `Property ${i}`,
value: `Value ${i}`,
selected: selectedIndices.includes(i),
}));
}