-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Labels
issue: bugIssue reporting a bugIssue reporting a bugseverity: mediumIf it breaks the basic use of the product but can be worked aroundIf it breaks the basic use of the product but can be worked aroundsource: typescriptSource is related to TypeScript (typings, tooling, ...)Source is related to TypeScript (typings, tooling, ...)status: pending reproductionWaiting for free time to reproduce the issue, or more informationWaiting for free time to reproduce the issue, or more information
Description
Bug report
Required System information
- Node.js version: 18.15.0
- yarn version: 1.22.19
- Strapi version: 4.11.5
- Database: sqlite
- Operating system: Ubuntu WSL on Windows 11
- Is your project Javascript or Typescript: Typescript
Describe the bug
I'm currently trying to extend the Strapi interface with custom keys in typescript.
I've seen that this feature has been implemented with pr #13108 but it doesn't seem to work anymore.
Steps to reproduce the behavior
- Create a new project with typescript
- Add the
index.d.tsas mentioned in the pr
import '@strapi/strapi'
declare module '@strapi/strapi' {
interface StrapiInterface {
customAddMethod(n1: number, n2: number): number;
}
}- Set and use the custom method in the
src/index.tsfile
export default {
register({ strapi }: { strapi: Strapi }) {
// No type error when trying the access & set the `customAddMethod` method
strapi.customAddMethod = (n1, n2) => {
return n1 + n2;
};
},
bootstrap({ strapi }: { strapi: Strapi }) {
const result = strapi.customAddMethod(11, 31);
// This should print "42"
console.log(result);
},
};When not importing the Strapi type, the error is: "Cannot use namespace 'Strapi' as a type."
When importing it via import { Strapi } from '@strapi/strapi, the error is "Property 'customAddMethod' does not exist on type 'Strapi'"
Expected behavior
The newly added function should be available on the Strapi interface and not cause any typing problems.
Am I doing something wrong or is this currently not working anymore?
If it's currently not possible, is there an ETA for when it could be possible?
Metadata
Metadata
Assignees
Labels
issue: bugIssue reporting a bugIssue reporting a bugseverity: mediumIf it breaks the basic use of the product but can be worked aroundIf it breaks the basic use of the product but can be worked aroundsource: typescriptSource is related to TypeScript (typings, tooling, ...)Source is related to TypeScript (typings, tooling, ...)status: pending reproductionWaiting for free time to reproduce the issue, or more informationWaiting for free time to reproduce the issue, or more information
Type
Projects
Status
Fixed/Shipped