Oak-Digital / types-4-strapi-2

Automate the creation of typescript interfaces for your strapi 4 projects
MIT License
24 stars 4 forks source link

'ExtractNested' is declared but its value is never read. #31

Open AaronMcCloskey opened 11 months ago

AaronMcCloskey commented 11 months ago

When running the following script

"typegen": "t4s -o ./src/types -r load-strapi --prettier .prettierrc"

It outputs the following file in src/types/builtins/Media.ts

import { IMediaFormat } from './MediaFormat';
import { ExtractNested } from './ExtractNested';
import { ExtractFlat } from './ExtractFlat';
import { RequiredBy } from './RequiredBy';
export interface IMedia<Populate extends string | never = never> {
  id: number;
  attributes: RequiredBy<
    {
      formats?: {
        thumbnail?: IMediaFormat | null;
        large?: IMediaFormat | null;
        medium?: IMediaFormat | null;
        small?: IMediaFormat | null;
      } | null;
      name: string;
      hash: string;
      ext: string;
      mime: string;
      url: string;
      provider: string;
      previewUrl: string | null;
      provider_metadata: string | null;
      alternativeText: string | null;
      caption: string | null;
      width: number | null;
      height: number | null;
      size: number;
    },
    ExtractFlat<Populate>
  >;
}

It imports ExtractNested, but is never used.

Which causes the Strapi app to exit, and because I Generate interfaces as soon as you create/modify/delete new components or content types the Strapi application exists everytime I create, updated or delete a collection.

Current solution is use an eslint plugin eslint-plugin-unused-imports and running a eslint --fix ./src/types --ext .js,.jsx,.ts,.tsx command after my typegen command in my src/extensions/content-type-builder/strapi-server.ts file. This will remove the unused import and prevent the Strapi app from exiting.

Alexnortung commented 11 months ago

Thanks for submitting this issue, I think I may have been a bit lazy in that implementation and not use dependency injection correctly.