Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled type warnigns #8

Open
yackinn opened this issue Mar 11, 2022 · 7 comments
Open

Unhandled type warnigns #8

yackinn opened this issue Mar 11, 2022 · 7 comments

Comments

@yackinn
Copy link

yackinn commented Mar 11, 2022

Describe the bug
We can see a lot of unhandled type warnigns in the terminal output on load of any resource in the admin panel.

Installed libraries and their versions
"@adminjs/express": "^4.1.0"
"@adminjs/mikroorm": "^1.1.0"
"@adminjs/nestjs": "^4.0.0"
"@mikro-orm/core": "^5.0.5"

To Reproduce
Steps to reproduce the behavior:

  1. Login
  2. Click on resource

Expected behavior
No unhandled type warning.

Screenshots
That's the console output.

Unhandled type: string
Unhandled type: string
Unhandled type: Date
Unhandled type: Date
Unhandled type: Date
Unhandled type: Date
Unhandled type: string
Unhandled type: string
Unhandled type: object
Unhandled type: object
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: string
Unhandled type: Date
Unhandled type: Date
Unhandled type: Date

AdminJSOptions with schema

@Entity({ customRepository: () => UserRepository })
export class User extends OmputBaseEntity {
  [EntityRepositoryType]?: UserRepository;

  @Property({ unique: true, columnType: 'varchar(255)' })
  @IsEmail()
  email: string;

  @Property({ hidden: true, columnType: 'varchar(255)' })
  password: ComparablePassword;

  @Property({ nullable: true })
  age?: number;

}

Desktop (please complete the following information if relevant):

  • OS: Macos Monterey
  • Browser Chrome
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.
That's our module setup using Nestjs.

AdminModule.createAdminAsync({
      inject: [MikroORM],
      useFactory: async (orm: MikroORM) => {
        return {
          adminJsOptions: {
            rootPath: '/admin',
            resources: [
              {
                resource: {
                  model: User,
                  orm,
                },
              }
            ]
          }
        };
      }
    }),
@dziraf
Copy link
Collaborator

dziraf commented Mar 15, 2022

Your model doesn't seem to have Date or object data types, where do they come from?

@yackinn
Copy link
Author

yackinn commented Mar 15, 2022

@Entity({ abstract: true })
export abstract class OmputBaseEntity {
  @PrimaryKey()
  id: string = v4();

  @Property({ hidden: true })
  createdAt: Date = new Date();

  @Property({ hidden: true, nullable: true, onUpdate: () => new Date() })
  updatedAt?: Date;

@dziraf
That's what the base entity looks like.
Are the types incorrect for adminjs?

@dziraf
Copy link
Collaborator

dziraf commented Mar 28, 2022

Transferring to adminjs-mikroorm repository. The types might be correct but they need to be mapped for a specific ORM adapter. I'm not sure why MikroORM uses Javascript types for columns now while it used database types previously e. g. timestamptz so I'll have to take a look.

You should be able to set a specific type in your resource options for each property in the meantime

@dziraf dziraf transferred this issue from SoftwareBrothers/adminjs Mar 28, 2022
@rubiin
Copy link

rubiin commented Apr 8, 2022

Similar to ArrayType . For fixing date type, I can do a pr

    let type: PropertyType = DATA_TYPES[this.column.columnTypes[0].toLowerCase()]
      || DATA_TYPES[this.column.type.toLowerCase()];

This should fix for date. I just checked locally

@dziraf
Copy link
Collaborator

dziraf commented Apr 8, 2022

@rubiin Go ahead. Unfortuantely I don't have any active project with MikroORM at the moment to investigate those issues. We do have a dev repo: https://github.com/SoftwareBrothers/adminjs-dev but it would still require a lot of work to reproduce various ORM-specific types. I personally prefer if ORMs provide database types since it's easier to map across packages

@vincentwinkel
Copy link

vincentwinkel commented Jul 16, 2022

What about this issue? I also have plenty of errors like that (only with Date).

adminjs 5.10.0
@adminjs/mikroorm 1.1.1

[EDIT] The solution proposed by @rubiin works like a charm in my case.

@vincentwinkel
Copy link

Still no PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants