mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: add arrays to IndexedStorage typings
Signed-off-by: Wouter Termont <woutermont@gmail.com>
This commit is contained in:
parent
df9062cfc5
commit
ccc006695f
@ -8,17 +8,20 @@ export const INDEX_ID_KEY = 'id';
|
|||||||
* Valid values are `"string"`, `"boolean"`, `"number"` and `"id:TYPE"`,
|
* Valid values are `"string"`, `"boolean"`, `"number"` and `"id:TYPE"`,
|
||||||
* with TYPE being one of the types in the definition.
|
* 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.
|
* 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.
|
* A `?` can be appended to the type to indicate this key is optional.
|
||||||
*/
|
*/
|
||||||
export type ValueTypeDescription<TType = string> =
|
export type ValueTypeDescription<TType = string> =
|
||||||
`${('string' | 'boolean' | 'number' | (TType extends string ? `${typeof INDEX_ID_KEY}:${TType}` : never))}${
|
`${('string' | 'boolean' | 'number' | (TType extends string ? `${typeof INDEX_ID_KEY}:${TType}` : never))}${
|
||||||
|
'[]' | ''}${
|
||||||
'?' | ''}`;
|
'?' | ''}`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a {@link ValueTypeDescription} to the type it should be interpreted as.
|
* Converts a {@link ValueTypeDescription} to the type it should be interpreted as.
|
||||||
*/
|
*/
|
||||||
export type ValueType<T extends ValueTypeDescription> =
|
export type ValueType<T extends ValueTypeDescription> =
|
||||||
(T extends 'boolean' | 'boolean?' ? boolean : T extends 'number' | 'number?' ? number : string) |
|
(T extends `${infer E extends ValueTypeDescription}[]${'?' | ''}` ? ValueType<E>[] :
|
||||||
|
T extends 'boolean' | 'boolean?' ? boolean : T extends 'number' | 'number?' ? number : string) |
|
||||||
(T extends `${string}?` ? undefined : never);
|
(T extends `${string}?` ? undefined : never);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user