From ccc006695f91e7955321b1ea9833c11532bdf742 Mon Sep 17 00:00:00 2001 From: Wouter Termont Date: Mon, 11 Mar 2024 13:20:41 +0100 Subject: [PATCH] feat: add arrays to IndexedStorage typings Signed-off-by: Wouter Termont --- src/storage/keyvalue/IndexedStorage.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/storage/keyvalue/IndexedStorage.ts b/src/storage/keyvalue/IndexedStorage.ts index 9ecff8c1a..19e2154f8 100644 --- a/src/storage/keyvalue/IndexedStorage.ts +++ b/src/storage/keyvalue/IndexedStorage.ts @@ -8,17 +8,20 @@ export const INDEX_ID_KEY = 'id'; * Valid values are `"string"`, `"boolean"`, `"number"` and `"id:TYPE"`, * with TYPE being one of the types in the definition. * In the latter case this means that key points to an identifier of the specified type. + * A `[]` can be appended to the type to indicate the value is an array. * A `?` can be appended to the type to indicate this key is optional. */ export type ValueTypeDescription = `${('string' | 'boolean' | 'number' | (TType extends string ? `${typeof INDEX_ID_KEY}:${TType}` : never))}${ + '[]' | ''}${ '?' | ''}`; /** * Converts a {@link ValueTypeDescription} to the type it should be interpreted as. */ export type ValueType = - (T extends 'boolean' | 'boolean?' ? boolean : T extends 'number' | 'number?' ? number : string) | + (T extends `${infer E extends ValueTypeDescription}[]${'?' | ''}` ? ValueType[] : + T extends 'boolean' | 'boolean?' ? boolean : T extends 'number' | 'number?' ? number : string) | (T extends `${string}?` ? undefined : never); /**