Trouble Rewriting Code for Effect/Schema with Zod Type Transformation
Hello I am trying to rewrite some code to
effect/schema
effect/schema
and i've run in to a problem.
The original zod type is
const LOCKFILE_MANAGER_SCHEMA = z .record( // NOTE: We normalize paths and checksums before constructing a record. z.string().transform(PathUtils.normalize), z.string().transform(MiniGit.toChecksum), ) .transform((t) => recordToTypedMap<PathUtils.PosixPath, MiniGit.Checksum>(t))/** * Converts a record to a typed map. */export function recordToTypedMap<K extends string, T>(record: Partial<Record<K, T>>): Map<K, T> { const map = new Map<K, T>() for (const path in record) { const key = path as K // NOTE: We can safely force unwrap here because we are iterating over keys. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion map.set(key, record[key]!) } return map}
const LOCKFILE_MANAGER_SCHEMA = z .record( // NOTE: We normalize paths and checksums before constructing a record. z.string().transform(PathUtils.normalize), z.string().transform(MiniGit.toChecksum), ) .transform((t) => recordToTypedMap<PathUtils.PosixPath, MiniGit.Checksum>(t))/** * Converts a record to a typed map. */export function recordToTypedMap<K extends string, T>(record: Partial<Record<K, T>>): Map<K, T> { const map = new Map<K, T>() for (const path in record) { const key = path as K // NOTE: We can safely force unwrap here because we are iterating over keys. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion map.set(key, record[key]!) } return map}
const LOCKFILE_MANAGER_SCHEMA2 = S.transform( S.record(PathUtils.posixPath, MiniGit.toChecksum), // How would I define this part: to be of type that the recordToTypedMap returns? (t) => recordToTypedMap<PathUtils.PosixPath, MiniGit.Checksum>(t), (t) => typedMapToRecord<PathUtils.PosixPath, MiniGit.Checksum>(t), // Here should be the reverse fucntion right?)
const LOCKFILE_MANAGER_SCHEMA2 = S.transform( S.record(PathUtils.posixPath, MiniGit.toChecksum), // How would I define this part: to be of type that the recordToTypedMap returns? (t) => recordToTypedMap<PathUtils.PosixPath, MiniGit.Checksum>(t), (t) => typedMapToRecord<PathUtils.PosixPath, MiniGit.Checksum>(t), // Here should be the reverse fucntion right?)