You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/customize/typescript/react-hooks.mdx
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,27 +120,27 @@ Before using React Hooks, you need to install their dependencies and configure y
120
120
121
121
### Install required dependencies
122
122
123
-
The generated SDK with React Hooks has TanStack Query and Zod dependencies that should be listed in the SDK's `package.json`. However, you might need to install them explicitly in your application:
123
+
The generated SDK with React Hooks has TanStack Query as a dependency that should be listed in the SDK's `package.json`. Zod is bundled with the SDK. However, you might need to install TanStack Query explicitly in your application:
124
124
125
125
<CodeWithTabs>
126
126
```bash !!tabs npm
127
-
npm install @tanstack/react-query zod
127
+
npm install @tanstack/react-query
128
128
```
129
129
130
130
```bash !!tabs yarn
131
-
yarn add @tanstack/react-query zod
131
+
yarn add @tanstack/react-query
132
132
```
133
133
134
134
```bash !!tabs pnpm
135
-
pnpm add @tanstack/react-query zod
135
+
pnpm add @tanstack/react-query
136
136
```
137
137
138
138
</CodeWithTabs>
139
139
140
140
<Callouttitle="Note">
141
-
The Speakeasy-generated TypeScript SDK uses Zod for runtime type validation,
142
-
and TanStack Query powers the React hooks. These dependencies are required for
143
-
the SDK to function correctly.
141
+
The Speakeasy-generated TypeScript SDK bundles Zod for runtime type validation,
142
+
and TanStack Query powers the React hooks. TanStack Query is required for
It's important to note that Zod is a peer dependency.
329
+
Zod is bundled as a regular dependency in Speakeasy TypeScript SDKs.
330
330
331
-
The reason for listing Zod as a peer dependency is to use the user's installation of Zod if they have it. Every popular package manager, except for Yarn, says, "If the user doesn't have a peer dependency installed, I'm gonna go ahead and install it and make it available".
331
+
Speakeasy moved Zod from a peer dependency to a regular dependency to address Zod v4 runtime errors. This ensures the SDK always uses its own bundled Zod v3 even if the customer is using Zod v4, preventing version conflicts.
332
332
333
-
Why does Speakeasy use peer dependencies? There are situations where the `node_modules` tree ends up with multiple Zod versions if the user has a different version of Zod installed than what the SDK requires. For example:
333
+
Previously, there were situations where the `node_modules` tree could end up with multiple Zod versions if the user had a different version of Zod installed than what the SDK required. For example:
334
334
335
335
```text
336
336
node_modules/
@@ -340,7 +340,7 @@ node_modules/
340
340
zod/v3.23.5
341
341
```
342
342
343
-
If the SDK throws a Zod validation error, the user might have code like this:
343
+
If the SDK threw a Zod validation error, the user might have code like this:
344
344
345
345
```typescript
346
346
import { Sdk } from"sdk";
@@ -360,9 +360,9 @@ try {
360
360
}
361
361
```
362
362
363
-
The code at `branch1`will not evaluate to `true` because the runtime loaded the wrong `ZodError` version. Using peer dependencies helps prevent this Zod validation error.
363
+
The code at `branch1`would not evaluate to `true` because the runtime loaded the wrong `ZodError` version. By bundling Zod as a regular dependency, Speakeasy prevents this validation error and ensures consistent behavior.
364
364
365
-
Speakeasy SDKs wrap `ZodError`s with a custom error type declared in each SDK. In practice, the Zod error is hidden from users and gets them to only work with the error type exported from the SDK. In the future, we start listing Zod as a direct dependency and are unaware of other Zod installations the user might have.
365
+
Speakeasy SDKs wrap `ZodError`s with a custom error type declared in each SDK. In practice, the Zod error is hidden from users and gets them to only work with the error type exported from the SDK.
Copy file name to clipboardExpand all lines: guides/sdks/typescript-monorepo-tips.mdx
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,9 @@ The most common issue we see is dependency confusion. This happens when develope
18
18
19
19
### Why is this a problem?
20
20
21
-
Let's say a developer have Zod installed in their monorepo's root, and their Speakeasy SDK also uses Zod. They might run into a situation where code like this doesn't work:
21
+
Let's say a developer has Zod installed in their monorepo's root, and their Speakeasy SDK also uses Zod. With Speakeasy's bundled Zod dependency, this is no longer an issue since the SDK uses its own version of Zod v3, preventing conflicts with user installations of Zod v4.
22
+
23
+
Previously, developers might have run into a situation where code like this didn't work:
22
24
23
25
```typescript
24
26
try {
@@ -28,13 +30,13 @@ try {
28
30
});
29
31
} catch (err) {
30
32
if (errinstanceofZodError) {
31
-
//🚨 This check fails!
33
+
// This check could fail with peer dependencies!
32
34
console.log("Validation error:", err.errors);
33
35
}
34
36
}
35
37
```
36
38
37
-
The `instanceof` check fails because they're importing `ZodError` from a different instance of Zod than what the SDK is using. It's the same code, but JavaScript treats them as different classes.
39
+
The `instanceof` check could fail because they were importing `ZodError` from a different instance of Zod than what the SDK was using. By bundling Zod, Speakeasy eliminates this confusion.
0 commit comments