Summary
Provide examples of typescript typings in method prototypes, not just how to import elements rather than using require.
Why is it needed?
When trying to maintain code that is expected to have strict typing, this becomes difficult without an easy reference for what types to use for what calls.
Additionally, this can simplify coding as it allows IDEs to then do auto-completion and catch bugs earlier in the development process.
Suggested solution(s)
Update current examples showing how to write the code with the appropriate types defined. Some examples of what I would expect to see include:
import { RouteDefinition } from '@strapi/strapi`;
export default {
routes: [
{
method: 'GET',
path: '/articles/customRoute',
handler: 'api::api-name.controllerName.functionName', // or 'plugin::plugin-name.controllerName.functionName' for a plugin-specific controller
config: {
auth: false,
},
},
],
} satisfies RouteDefinition;
import { Strapi, factories, ControllerRequestContext } from "@strapi/strapi";
export default factories.createCoreController(
"api::restaurant.restaurant",
({ strapi }: { Strapi }) => ({
async find(ctx: ControllerRequestContext) {
const sanitizedQueryParams = await this.sanitizeQuery(ctx);
const { results, pagination } = await strapi
.service("api::restaurant.restaurant")
.find(sanitizedQueryParams);
const sanitizedResults = await this.sanitizeOutput(results, ctx);
return this.transformResponse(sanitizedResults, { pagination });
},
})
);
Related issue(s)/PR(s)
No response
Summary
Provide examples of typescript typings in method prototypes, not just how to import elements rather than using require.
Why is it needed?
When trying to maintain code that is expected to have strict typing, this becomes difficult without an easy reference for what types to use for what calls.
Additionally, this can simplify coding as it allows IDEs to then do auto-completion and catch bugs earlier in the development process.
Suggested solution(s)
Update current examples showing how to write the code with the appropriate types defined. Some examples of what I would expect to see include:
ctxshould be, and all I can confirm is it is notRequestContext):Related issue(s)/PR(s)
No response