Hi all,
I am trying to use the VSCode IntelliSense to autocomplete the types I have from my Strapi Content.
For example, I have the content type product, which created in the database the table products. Then in the code using VSCode I would like to be able to when using something like product. it will autocomplete with the available columns, for example name.
The place where I am trying to get this done is the life cycle of the content, therefore it is in the src/api/product/content-types/product/lifecycles.ts
I have tried without success to get this done “out-of-box”.
So far, I got this post, which talks about the use of Strapi types in the frontend. It suggest a plugin that might be useful in the backend as well.
Another useful post that is more of what I need is the one below:
This is about the auto-generated types, which can be manually done running yarn strapi ts:generate-types
Right now it is generating this:
export interface ApiProductProduct extends Schema.CollectionType {
collectionName: 'products';
info: {
singularName: 'product';
pluralName: 'products';
displayName: 'Products';
description: '';
};
options: {
draftAndPublish: false;
};
pluginOptions: {
i18n: {
localized: true;
};
};
attributes: {
name: Attribute.String &
Attribute.Required &
Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
active: Attribute.Boolean &
Attribute.SetPluginOptions<{
i18n: {
localized: false;
};
}>;
description: Attribute.Text &
Attribute.SetPluginOptions<{
i18n: {
localized: true;
};
}>;
products_prices: Attribute.Relation<
'api::product.product',
'oneToMany',
'api::products-price.products-price'
>;
createdAt: Attribute.DateTime;
updatedAt: Attribute.DateTime;
createdBy: Attribute.Relation<
'api::product.product',
'oneToOne',
'admin::user'
> &
Attribute.Private;
updatedBy: Attribute.Relation<
'api::product.product',
'oneToOne',
'admin::user'
> &
Attribute.Private;
localizations: Attribute.Relation<
'api::product.product',
'oneToMany',
'api::product.product'
>;
locale: Attribute.String;
};
}
Nevertheless, when I try to use that, returns just the id like in the images below.
In addition, when I hover over the Product it shows this:
type Product = {
id: ID;
} & {
[x: string]: unknown;
} & {}
What am I missing here? Does anyone could help me with that, please?
@excooo and @Convly do you have any inputs?
Thanks in advance
System Information
- Strapi Version: 4.25.1
- Operating System: Windows 11 (running WSL2 (5.15.133.1-microsoft-standard-WSL2) with Ubuntu 22.04.3 LTS)
- Database: MySQL
- Node Version: 18.20.2
- NPM Version: -
- Yarn Version: 1.22.19