-
Notifications
You must be signed in to change notification settings - Fork 382
Open
Description
Currently, there is no way to strongly type a keyval store that has only certain keys (each with its own value type).
For example:
interface DatabaseSchema extends DBSchema {
metadata:
| {
key: "foo";
value: { bar: number };
}
| {
key: "baz";
value: string;
};
}
...
const foo = await db.get("metadata", "foo");
// Type of `foo`: string | { bar: number } | undefinedWhat I would like is some way for a discriminated union (based on key type, obviously) to be detected and used.
The key passed to database functions would then be used to provide better typing.
One of my other ideas for what this could look like, instead of a discriminated union:
interface Metadata extends DBSchemaStore = {
foo: { bar: number };
baz: string;
};
interface DatabaseSchema extends DBSchema {
metadata: Metadata;
}
const foo = await db.get("metadata", "foo");
// Type of `foo`: { bar: number } | undefineddumbmatter, renspoesse and indianakernick
Metadata
Metadata
Assignees
Labels
No labels