-
Say I have some code that generates a store. The contents of the store can be statically infered. But there is no explicit typing here. Simply: const partOne = {
a: 15,
b: "z",
};
const partTwo = {
c: true,
}
// $ExpectType MapStore<{ a: number; b: string; c: boolean; }>
const $store = map({
...partOne,
...partTwo,
}); Later down the line I would like to use the type of the final Store contents. (I am probably spoiled a little by Zod’s type inference.) What would be the (subjectively) best way to infer this? My current solution: type StoreValue<Store extends ReadableAtom> = ReturnType<Store["get"]>; Usage: // $ExpectType { a: number; b: string; c: boolean; }
type myStore = StoreValue<typeof $store>; Am I missing something? Would it be interesting to land an infer helper in the .d.ts files? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
We already have https://github.com/nanostores/nanostores/blob/main/map/index.d.ts#L23 |
Beta Was this translation helpful? Give feedback.
We already have
StoreValue<Store>
type helper in library exportshttps://github.com/nanostores/nanostores/blob/main/map/index.d.ts#L23