Comments (2)
Thanks for the suggestion. I'll check with Strapi core engineers and see what we can do.
from documentation.
Hey,
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 controller config: { auth: false, }, }, ], } satisfies RouteDefinition;
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 notRequestContext
):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 }); }, }) );
This one is surprising, createCoreController
should already infer the correct types for the methods. You shouldn't need to manual add the context type 🤔
from documentation.
Related Issues (20)
- [Request]: Adding mdw to >all< routes of one content type HOT 1
- Clarify that you need to use .ts files when extending plugins if you use TypeScript HOT 1
- Data transfer - Test the transfer command locally - instructions do not work
- wrong resolve path in example HOT 1
- Missing deep object structure filtering? HOT 7
- DOCS: Complex filtering mentions fields which are not in the example
- DOCS: Deep filtering mentions fields which are not in the example
- [v5] defaultIndex is removed and not included in breaking changes HOT 2
- [Request]: Adding a guide on deploying Sprapi using cPanel HOT 6
- [Request]: HOT 1
- v5 documents completely change how lifecycles work, not documented as a breaking change HOT 13
- Get started Button is not redirecting to the docs HOT 3
- DOCS: EntintyService `findMany` returns Entry (not Entry[]) for singular types HOT 2
- Instructions on creating a middleware mention read but it probably should be find HOT 1
- entityService parameter documentation should include 'locale' HOT 1
- [Request]: How does strapi entity service work with transactions? HOT 1
- Default error classes confuse Unauthorized & Forbidden HOT 3
- [BUG] Missing notes about i18n plugin becoming core package HOT 3
- Swagger and openapi json files do not exists HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from documentation.