zapier / zapier-platform

The SDK for you to build an integration on Zapier
https://docs.zapier.com/platform
Other
348 stars 188 forks source link

feat(types): Type z.request responses; deprecate `.json` #895

Closed tkcranny closed 4 weeks ago

tkcranny commented 1 month ago

This adds generic parameters to the HttpResponse and RawHttpResponse types that allow them to specify what they're returning. If not provided the default is any, similar to the previous behaviour.

interface User {
  id: numner,
  name: string,
}

const resp = await z.request<User>('https://example.com/users');
resp.data.firstName // Error: Type `firstName` doesn't exist on type User, did you mean `name`.

Because of this note in the CLI docs, I've also marked the .json attribute on HttpResponse objects as @deprecated. It will now show up in the editor struck out, and suggest using .data instead. Is this deprecating .json correct in your opinion?

Screen Shot 2024-10-18 at 17 32 53