Skip to content

Custom Plugin - Register Component - Typescript #18724

@tobiasbenkner

Description

@tobiasbenkner

Bug report

Required System information

Environment: development
OS: darwin-arm64
Strapi Version: 4.14.5
Node/Yarn Version: yarn/1.22.19 npm/? node/v18.12.1 darwin arm64
Edition: Community
Database: sqlite
Typescript

Describe the bug

I am currently building a plugin in which I would like to register components. The data type Schema.Component does not provide all required attributes.

  • firstly, the info attribute is missing to define the display name
  • On the other hand, you have to add __filename__ and __schema__ so that you can add new collection-types in the content-type-builder.

Expected behavior

  • The data type Schema.Component should provide the attribute info
  • I don't want to set __filename__ and __schema__
    • __filename__ I don't have a filename
    • __schema__ I repeat what I have already defined

Code snippets

This code is working

import { Strapi } from "@strapi/strapi";

export default async ({ strapi }: { strapi: Strapi }) => {
  const attributes = { attribut1: { type: "string" } };
  const collectionName = "components_huhu_minis";
  const info = { displayName: "mini", icon: "alien" };
  const __filename__ = "";

  const schema = {
    collectionName: collectionName,
    info: info,
    options: {},
    attributes: attributes,
    __filename__: __filename__,
    __schema__: {
      collectionName: collectionName,
      info: info,
      options: {},
      attributes: attributes,
      __filename__: __filename__,
    },
    uid: "huhu.mini",
    category: "huhu",
    modelType: "component",
    modelName: "mini",
    globalId: "ComponentHuhuMini",
  } as any;

  strapi.components[schema.uid] = schema;
};

This schema is correct according to the Typescript, but leads to problems because the mentioned attributes are missing

const aValidSchemaTypeButProduceErrors: Schema.Component = {
    collectionName: collectionName,
    options: {},
    attributes: { attribut1: { type: "string" } },
    uid: "huhu.mini",
    category: "huhu",
    modelType: "component",
    modelName: "mini",
    globalId: "ComponentHuhuMini",
  };

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions