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
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:
for instances where you are defining a default export (the type in my example I made up as I don't know the appropriate type)
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 controllerconfig: {auth: false,},},],}satisfiesRouteDefinition;
That could be a good idea. Another one we have is potentially export typed factories to eliminate the need for manual typings + be able to propose the same benefits for both JS and TS projects
where you are defining methods, then ensure to include the types (again unsure of what ctx should be, and all I can confirm is it is not RequestContext):
This one is surprising, createCoreController should already infer the correct types for the methods. You shouldn't need to manual add the context type 🤔
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:
ctx
should be, and all I can confirm is it is notRequestContext
):Related issue(s)/PR(s)
No response
The text was updated successfully, but these errors were encountered: