Repository: fabien0102/ts-to-zod
Pull request #178 (2023-11-13 20:49:24)

[Fix] Handle ExpressionWithTypeArguments in extend clause
# Why

Type identifiers in extension clauses such as 
```ts
export interface Superhero extends Pick<Person, "name"> {
  id: number,
};
```
were not extracted correctly thus leading to incomplete generations.

schiller-manuel: can you add another test case for `Omit` please?
tvillaren: Added 2 more use case (`Omit` & `Partial`), handled the same as all supported helpers. 
codecov-commenter: ## [Codecov](https://app.codecov.io/gh/fabien0102/ts-to-zod/pull/178?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`cb9618f`)](https://app.codecov.io/gh/fabien0102/ts-to-zod/commit/cb9618fe55b75de7065e0c7d9dd24f84ee53287a?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) 97.35% compared to head [(`7504e3d`)](https://app.codecov.io/gh/fabien0102/ts-to-zod/pull/178?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD) 97.36%.


:exclamation: Your organization needs to install the [Codecov GitHub app](https://github.com/apps/codecov/installations/select_target) to enable full functionality.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
+ Coverage   97.35%   97.36%   +0.01%     
==========================================
  Files          14       14              
  Lines         718      721       +3     
  Branches      293      295       +2     
==========================================
+ Hits          699      702       +3     
  Misses         19       19              
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/fabien0102/ts-to-zod/pull/178?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Fabien+BERNARD).


Patch:
diff --git a/.github/workflows/release-please.yaml b/.github/workflows/release-please.yaml
index bf49b33..6ba5438 100644
--- a/.github/workflows/release-please.yaml
+++ b/.github/workflows/release-please.yaml
@@ -19,7 +19,7 @@ jobs:
         if: ${{ steps.release.outputs.release_created }}
       - uses: actions/setup-node@v1
         with:
-          node-version: 12
+          node-version: 20
           registry-url: 'https://registry.npmjs.org'
         if: ${{ steps.release.outputs.release_created }}
       - run: yarn
diff --git a/src/utils/traverseTypes.ts b/src/utils/traverseTypes.ts
index 3afb4ae..b74b3a2 100644
--- a/src/utils/traverseTypes.ts
+++ b/src/utils/traverseTypes.ts
@@ -84,7 +84,13 @@ export function getExtractedTypeNames(
         extensionTypes.forEach((extensionTypeNode) => {
           const typeName = extensionTypeNode.expression.getText(sourceFile);
 
-          referenceTypeNames.add(typeName);
+          if (extensionTypeNode.typeArguments) {
+            extensionTypeNode.typeArguments.forEach((t) => handleTypeNode(t));
+          }
+
+          if (typeScriptHelper.indexOf(typeName) === -1) {
+            referenceTypeNames.add(typeName);
+          }
         });
       });
     }


Test patch:
diff --git a/src/utils/traverseTypes.test.ts b/src/utils/traverseTypes.test.ts
index 565ea3f..7b91b5f 100644
--- a/src/utils/traverseTypes.test.ts
+++ b/src/utils/traverseTypes.test.ts
@@ -63,6 +63,46 @@ describe("traverseTypes", () => {
       expect(result).toEqual(["Superhero", "Person", "Person2"]);
     });
 
+    it("should extract type referenced in extend clause with Pick helper", () => {
+      const source = `
+            export interface Superhero extends Pick<Person, "name"> {
+                id: number,
+            }`;
+
+      const result = extractNames(source);
+      expect(result).toEqual(["Superhero", "Person"]);
+    });
+
+    it("should extract type referenced in extend clause with Omit helper", () => {
+      const source = `
+            export interface Superhero extends Omit<Person, "name"> {
+                id: number,
+            }`;
+
+      const result = extractNames(source);
+      expect(result).toEqual(["Superhero", "Person"]);
+    });
+
+    it("should extract type referenced in extend clause with Partial helper", () => {
+      const source = `
+            export interface Superhero extends Partial<Person, "name"> {
+                id: number,
+            }`;
+
+      const result = extractNames(source);
+      expect(result).toEqual(["Superhero", "Person"]);
+    });
+
+    it("should extract type referenced in extend clause with Record helper", () => {
+      const source = `
+            export interface Superhero extends Record<string, Person2> {
+                id: number,
+            }`;
+
+      const result = extractNames(source);
+      expect(result).toEqual(["Superhero", "Person2"]);
+    });
+
     it("should extract type referenced in property as array", () => {
       const source = `
             export interface Superhero {