Skip to content

Commit

Permalink
fix(deserializer): infer output from TLinksSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed May 21, 2024
1 parent e928f8c commit 24402b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/deserializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ type AppendLinks<
TDeserializer extends AnyResourceDeserializer,
TBase,
TLinksSchema extends LinksSchema | undefined = InferPropertyType<TDeserializer, "linksSchema">,
> = TLinksSchema extends LinksSchema ? TBase & { $links: z.output<LinksSchema> } : TBase;
> = TLinksSchema extends LinksSchema ? TBase & { $links: z.output<TLinksSchema> } : TBase;

type AppendMeta<
TDeserializer extends AnyResourceDeserializer,
Expand Down
26 changes: 26 additions & 0 deletions test/selector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,32 @@ describe("createResourceSelector", () => {
},
});
});

it("should parse resource links", () => {
const selector = createResourceSelector({
type: "article",
linksSchema: z.object({
self: z.string(),
}),
});

const result = selector({
data: {
id: "ID-p",
type: "article",
links: { self: "foo" },
},
});

expect(result).toEqual({
data: {
id: "ID-p",
$links: {
self: "foo",
},
},
});
});
});

describe("createNullableResourceSelector", () => {
Expand Down

0 comments on commit 24402b2

Please sign in to comment.