-
|
I get correct autocompletion of properties returned from middleware in Is there a way to tell TypeScript to report error if non-existing property is accessed? EDIT: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
|
Hi @pycanis! I'm Dosu and I’m helping the express-zod-api team. TypeScript allows access to non-existent properties on your middleware output because the initial context type is defined as Recent versions (v24.4.2+) have improved this, and v25 will make TypeScript errors even more explicit when you access undefined properties cite. There’s no config option to change this, but you can enforce stricter type checking by making sure your middleware outputs are explicitly typed and don’t include index signatures. If you try to access a property not present in the context type, TypeScript should flag it as If you want to guarantee compile-time errors for typos or non-existent properties, keep your middleware outputs as explicit as possible and avoid using Example: const factory = defaultEndpointsFactory
.addMiddleware(createMiddleware({
handler: async () => ({ user: { id: "123" } }),
}));
factory.build({
handler: ({ options }) => {
// options.user is OK
// options.foo will be type 'never' (error if used)
}
});If you’re still seeing unwanted property access, double-check your middleware output types and your tsconfig strictness settings. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
|
@pycanis , what is your version of |
Beta Was this translation helpful? Give feedback.
🚀 Fixed in version
26.3.1Thank you for the contribution, @pycanis
@dosu, learn