feat: add generic type for property value
This commit is contained in:
@@ -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 => ({
|
||||
|
||||
@@ -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),
|
||||
}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user