From 2b9f2a4bd8fabb4f9747e79a273e6766fef3998e Mon Sep 17 00:00:00 2001 From: Alex Komoroske Date: Sat, 24 Jun 2023 15:34:40 -0700 Subject: [PATCH] Fix typescript typing of makeSeedData to have the proper typescript types. makeNestedSeedData is harder to do because of the recursive typing. Part of #2. --- src/types.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/types.ts b/src/types.ts index d9d8f22..ab58218 100644 --- a/src/types.ts +++ b/src/types.ts @@ -156,8 +156,7 @@ const makeNestedSeedData = , Shape extends z.Z const makeSeedData = , Shape extends z.ZodRawShape>(config : SeedDataConfiguration) => { const entries = TypedObject.entries(config.properties).map(entry => [entry[0], makeSeedReferenceProperty(entry[1])]); - //TODO: this cast is actually wrong... but it still works as expected? - const modifiedProperties = Object.fromEntries(entries) as Shape; + const modifiedProperties = Object.fromEntries(entries) as {[k in keyof Shape] : z.ZodUnion<[typeof seedReference, Shape[k]]>}; return seedDataBase.extend({ type: config.type, }).extend( @@ -232,7 +231,8 @@ export const seedData = z.discriminatedUnion('type', [ //TODO: SeedData has the wrong typescript shape because of the supicious `as //Shape` in makeSeedData and makeNestedSeedData. This makes the Typescript types //of SeedData not agree with the zod types (which are correctly structured), and -//make Typescript erroneously think that properties that are sub-seeds have no values. +//make Typescript erroneously think that properties that are sub-seeds have no +//values. It's been fixed in makeSeedData, but not makeNestedSeedData. export type SeedData = z.infer; export type SeedDataType = ExpandedSeedData['type'];