vapabase
vapabase2mo ago

Deno / Zod / ts-zod-decorators

Hi guys - I'm trying to use ts-zod-decorators as a means of validating function arguments. The library provides two decorators Validate and ZodInput. You can see in this screen clip I provide my deno.json, my little convenience files that bring relevant Zod features together, and then my class, having the method that I want to apply validation to. I'm getting an error message of "Decorators are not valid here" when I try to apply the decorator to the function argument. Literally just installed Deno, so on the latest version there. Any guidance would be much appreciated. I'm pretty intermediate level with Typescript and a newby with Deno. Having seen the YouTube 1.4 announcement, it looks like we can't use decorators on arguments?
No description
3 Replies
Deno AI Helper
Deno AI Helper2mo ago
I apologize, but I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided, it seems like you might be encountering an issue with TypeScript decorators. In TypeScript, decorators are an experimental feature and are not yet part of the ECMAScript standard. They can be applied to classes, methods, accessors, properties, or parameters, but there are some limitations. If you're seeing an error message saying "Decorators are not valid here," it could be due to a syntax error or a misunderstanding of where decorators can be applied. From your message, it seems like you're trying to apply a decorator to a function argument, which is not currently supported in TypeScript. Decorators can be applied to method parameters, but not directly to standalone function arguments. Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you're using TypeScript decorators, make sure you have enabled the experimental decorators feature in your tsconfig.json file by setting "experimentalDecorators": true. Additionally, ensure that you're using the decorators in a supported context according to TypeScript's decorator documentation. If you continue to experience issues, you might want to look into the documentation or community resources for ts-zod-decorators or consider alternative validation strategies that are compatible with your current setup.
marvinh.
marvinh.2mo ago
According to the spec (see https://github.com/tc39/proposal-decorators) decorators in JavaScript can be applied to: 1. Classes 2. Class fields 3. Class methods 4. Class accessors A function parameter is neither of these, so decorators won't work there
vapabase
vapabase2mo ago
Thanks