Skip to content

Commit

Permalink
Fix typescript typing of makeSeedData to have the proper typescript t…
Browse files Browse the repository at this point in the history
…ypes.

makeNestedSeedData is harder to do because of the recursive typing.

Part of #2.
  • Loading branch information
jkomoros committed Jun 24, 2023
1 parent 05e73d1 commit 2b9f2a4
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,7 @@ const makeNestedSeedData = <Kind extends z.ZodLiteral<string>, Shape extends z.Z

const makeSeedData = <Kind extends z.ZodLiteral<string>, Shape extends z.ZodRawShape>(config : SeedDataConfiguration<Kind, Shape>) => {
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(
Expand Down Expand Up @@ -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<typeof seedData>;

export type SeedDataType = ExpandedSeedData['type'];
Expand Down

0 comments on commit 2b9f2a4

Please sign in to comment.