Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template Literal handling #217

Merged
merged 11 commits into from Mar 29, 2024

Conversation

tvillaren
Copy link
Collaborator

Why

This PR implement supports for #64 and #214

Issue #64

Transforms

export enum Foo {
  Bar = 'Bar',
  Baz = 'Baz',
}

export interface Party {
  Time: `${Foo}`;
}

into

export const fooSchema = z.nativeEnum(Foo);
export const partySchema = z.object({
  Time: z.union([z.literal('Bar'), z.literal('Baz')]),
});

Issue #214

Transforms

export type Prefix = "large" | "high";
export type Subfix = "back" | "front";
export type Joint = `${Prefix}-${Subfix}`;

into

export const PrefixSchema = z.union([
  z.literal("large"),
  z.literal("high"),
]);

export const SubfixSchema = z.union([
  z.literal("back"),
  z.literal("front"),
]);

export const JointSchema =  z.union([
  z.literal("large-back"),
  z.literal("large-front"),
  z.literal("high-back"),
  z.literal("high-front"),
]);

@codecov-commenter
Copy link

codecov-commenter commented Mar 26, 2024

Codecov Report

Attention: Patch coverage is 82.92683% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 95.98%. Comparing base (9e52cca) to head (1ecadc7).
Report is 1 commits behind head on main.

Files Patch % Lines
src/core/generateZodSchema.ts 73.07% 14 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
- Coverage   97.26%   95.98%   -1.28%     
==========================================
  Files          16       18       +2     
  Lines         840      922      +82     
  Branches      340      368      +28     
==========================================
+ Hits          817      885      +68     
- Misses         23       37      +14     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@schiller-manuel
Copy link
Collaborator

Does it make sense to add tests to cover the unhit branches?
e.g. https://app.codecov.io/gh/fabien0102/ts-to-zod/pull/217/blob/src/core/generateZodSchema.ts#L1010

it("should generate all combinations of 1 empty array", () => {
const arrays = [[]];
const result = generateCombinations(arrays);
expect(result).toEqual([""]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the result not an empty array []?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason, it would probably be more logical to be empty indeed.
Updated accordingly.

@tvillaren
Copy link
Collaborator Author

Does it make sense to add tests to cover the unhit branches? e.g. https://app.codecov.io/gh/fabien0102/ts-to-zod/pull/217/blob/src/core/generateZodSchema.ts#L1010

I don't think it does, other warnings in the lib are not covered either (and I believe those are the only non-covered branches)

@schiller-manuel
Copy link
Collaborator

LGTM
let's merge!

@schiller-manuel schiller-manuel merged commit e21ea92 into fabien0102:main Mar 29, 2024
2 of 4 checks passed
@tvillaren tvillaren deleted the feat-template-literal-214 branch March 29, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants