Strapi v4.2.0 beta with TypeScript support & Dark Mode

Hey everyone!

We’re happy to share our progress on two very awaited features: TypeScript support and the Dark Mode. Both features are available in the beta version of v4.2.0

To test them, please run a command:

npx create-strapi-app@beta my-app --ts

Here’s the beta version of the Dark Mode documentation and user guide, and TypeScript documentation.

Please note that both features are a work in progress and the beta version should not be used in production. We’re sharing them with you to have feedback on an early stage :slightly_smiling_face:

Here’s the Github release for more information.

Please share your feedback in this thread!

22 Likes

Hey there, I am really excited about the typescript support! :slight_smile:
Is there an updated documentation, though, showing some simple customization e.g. how to customize a single controller with typescript?

I tried that out, but wasn’t able to replace just the find function for example of a collection type controller, because:

  1. The factories.d.ts definition of the createCoreController function requires a complete Controller type input, meaning if I want to provide that input parameter, typescript requires me to define a complete set of the functions find, findOne, create, update, delete, transformResponse, sanitizeOutput, sanitizeInput. That should not be necessary, though, as the actual implementation of the createCoreController function is checking which functions are provided and will overwrite just those. Shouldn’t the type definition use Partial<> or something here to allow only a subgroup of the functions as input?

  2. Also the input does not accept a function, but just the Controller type directly. Means, I cannot inject the strapi object into my controller functions. Again, the actual implementation of createCoreController has a check (typeof cfg === 'function'), but the type definition does not allow me a function as parameter.

1 Like

Hi @rom, happy that you are excited about TypeScript support! :partying_face:
The Documentation team is working closely with developers to add more documentation about TypeScript support in Strapi soon. We will keep you posted :slight_smile:

2 Likes

Hello there! I’m also very happy about Typescript support on Strapi.

Just in addition to @rom’s comment, this also happens with createCoreRouter.

We can just go and add everything manually but it is a little bit tedious just for adding a config-option or any other parameter. The Partial<> approach or similar looks like a good solution for this.

Thanks! :smiley: :wave:

The npx command is actually npx create-strapi-app@beta my-app --ts without the brackets.

Is there any way to follow the progress on the Typescript implementation? I’m trying to migrate a v3 Strapi written in Typescript (custom implementation) to the new v4.2.0, but I can see there is still a lot of work in progress.

Thus far Strapi v4.2.0 beta.0 and beta.1 throw errors when running npm start.

❯ npm start
╰─ npm start                                                                                                                                                ─╯
> my-project@0.1.0 start /Users/user/org/my_project
> strapi start

[2022-04-25 20:25:13.210] debug: ⛔️ Server wasn't able to start properly.
[2022-04-25 20:25:13.212] error: Unknown dialect undefined
Error: Unknown dialect undefined
    at getDialectClass (/Users/user/org/my_project/node_modules/@strapi/database/lib/dialects/index.js:12:13)
    at getDialect (/Users/user/org/my_project/node_modules/@strapi/database/lib/dialects/index.js:19:23)
    at new Database (/Users/user/org/my_project/node_modules/@strapi/database/lib/index.js:27:20)
    at Function.Database.init (/Users/user/org/my_project/node_modules/@strapi/database/lib/index.js:73:33)
    at Strapi.bootstrap (/Users/user/org/my_project/node_modules/@strapi/strapi/lib/Strapi.js:385:30)
    at Strapi.load (/Users/user/org/my_project/node_modules/@strapi/strapi/lib/Strapi.js:448:16)
    at async Strapi.start (/Users/user/org/my_project/node_modules/@strapi/strapi/lib/Strapi.js:196:9)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! my-project@0.1.0 start: `strapi start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the my-project@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Looks like the workaround is posted here.

// package.json
...
"scripts": [
  "start": "strapi start dist",
],
...

When trying to add plugins for s3, ran into this :

[2022-06-07 16:20:19.181] debug: ⛔️ Server wasn't able to start properly.
[2022-06-07 16:20:19.182] error: provider.init is not a function
TypeError: provider.init is not a function

Also unable to add other plugins in same file.

Hi Deepark can you finally resolve this problem? I have the same issue and it seems that all the configurations all well implemented in my case.