Add example for Strapi type extension

This commit is contained in:
Convly 2022-04-12 15:30:09 +02:00
parent 60a26e08fc
commit 1aff33e1d1
2 changed files with 22 additions and 0 deletions

7
examples/kitchensink-ts/index.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import '@strapi/strapi';
declare module '@strapi/strapi' {
interface StrapiInterface {
customAddMethod(n1: number, n2: number): number;
}
}

View File

@ -0,0 +1,15 @@
export default {
register({ strapi }: { strapi: Strapi }) {
// No error when trying the access & set the
strapi.customAddMethod = (n1, n2) => {
return n1 + n2;
};
},
bootstrap({ strapi }: { strapi: Strapi }) {
const result = strapi.customAddMethod(12, 32);
// This should print "42"
console.log(result);
},
};