import type { Unit } from 'effector'; type Shape = { [key: string]: Unit }; type UnprefixedKey = Original extends `$${infer Unprefixed}` ? Unprefixed : Original; type PrefixedKey = `$${Key}`; export type Unprefixed = { [key in UnprefixedKey]: T extends { [inner in key]: unknown } ? T[key] : key extends string ? T[PrefixedKey] : never; }; export function removeStorePrefix(shape: T): Unprefixed { return Object.keys(shape).reduce((acc, key) => { const unprefixedKey = key.replace(/^\$/, '') as UnprefixedKey; // @ts-expect-error acc[unprefixedKey] = shape[key]; return acc; }, {} as Unprefixed); }