Search code examples
typescriptstrapi

Typescript throwing an error every time I try to add a new collection type in Strapi


I have a new install of the latest strapi (4.11.1), and am new to the platform. I'm using Postgres as my backend. Everything was going splendidly until this morning, when trying to add a new collection to my existing definitions. At first I called it "Application", and went through the definition phase, and got an error like this:

src/api/application/controllers/application.ts:7:47 - error TS2345: Argument of type '"api::application.application"' is not assignable to parameter of type 'ContentType'.

7 export default factories.createCoreController('api::application.application');

src/api/application/routes/application.ts:7:43 - error TS2345: Argument of type '"api::application.application"' is not assignable to parameter of type 'ContentType'.

... 

Found 3 error(s).

Other related errors were snipped for the sake of brevity.

Thinking that perhaps "Application" was a reserved keyword that I wasn't being warned about, I deleted the "application" folder in src/api, and started over, this time calling it "Package". Same error, new name. So I tried again, but with something that could not possibly be a reserved keyword - "Hutzpah". Same problem. I also stopped trying to do a full definition of the collection type, and only added a single text string called "Name". Same problem. These are the only errors I get.

It seems that for some reason, strapi is not adding the type interface version of the JSON "schema" into types/generated/contentTypes.d.ts and this omission is what's causing the errors, but I'm not familiar enough with strapi to understand why this might be the case, or if this is a red herring.

Any help would be most appreciated. Thank you for your time.


Solution

  • I ran today into the same issue. Same version of strapi and with typescript as well. Did you generate typings as its mentioned here? https://docs.strapi.io/dev-docs/typescript#generate-typings-for-project-schemas

    I figured out it might be the issue, so I removed the generated folder "types" with all its content and now it works fine