-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript service typing doesn't allow addition of custom services #14035
Comments
even the code in this issue doesn't work |
putting any as the return type completely fixed the issue such that this works without a problem: export type GenericService = Partial<Service> & {
[method: string | number | symbol]: <T = any>(...args: any) => any;
};
export default factories.createCoreService('api::something.something', ({ strapi }) => {
return {
// service functions or properties here
async someFunction (a: number): Promise<number[]> {
return [1, 2, 3];
},
async someFunction2<T> (a: number): Promise<T[]> {
return [1 as T];
},
};
}); notice the generic example at the end, it still works |
@emahuni how did you change GenericService without editing factories in lib? Without it I have error on createCoreService |
I created my own typings file then added that type export type GenericService = Partial<Service> & {
[method: string | number | symbol]: <T = any>(...args: any) => any;
}; If you put this directly in the file you're using this it'll still work, putting it into a separate typings file makes it cleaner and reusable. |
Bug report
Required System information
4.3.2
Describe the bug
Typescript service typing doesn't allow addition of custom services, when adding a new service such as follows:
It throws a typing error as follows:
Expected behavior
Should work and not throw an error
The text was updated successfully, but these errors were encountered: