adminjs icon indicating copy to clipboard operation
adminjs copied to clipboard

Resource fields don't show typing informations

Open asynched opened this issue 2 years ago • 1 comments

Describe the bug No typing information is showed on editors when trying to add a new resource to the resource array in the AdminJS instance.

Installed libraries and their versions

  • adminjs@^6.0.0
  • @adminjs/express@^5.0.0
  • @adminjs/mongoose@^3.0.0

To Reproduce

  1. Create a new AdminJS instance
  2. In the property resource of the options object, add an array with a resource
  3. Typing won't be available for the resource item

I've created a repo for reproducing the bug: https://github.com/asynched/adminjs-resource-fields-repro

Expected behavior Expected to have typing schema for a resource entry in the array of resources.

Screenshots image

Additional context The problem seems to be related to the AdminJSOptions type definition, where the resource type is Array<ResourceWithOptions | any>, removing the any type seems to fix the problem (as the screenshot below shows).

image

The editor I'm currently using is VSCode, I don't know if the problem is specific to VSCode.

asynched avatar Jul 17 '22 04:07 asynched

I think any comes from you being able to pass any ORM/ODM model, e.g. Typeorm entity, Mongoose model, etc. We could probably fix this by introducing generic T type for AdminJSOptions which would be a type for your entity. This would cause typing problems if you're using multiple ORMs/ODMs though. I'll investigate how we can type this better.

dziraf avatar Jul 20 '22 11:07 dziraf

This is a duplicate of https://github.com/SoftwareBrothers/adminjs/issues/656

krzysztofstudniarek avatar Aug 16 '22 09:08 krzysztofstudniarek