Vincit / objection.js

An SQL-friendly ORM for Node.js
https://vincit.github.io/objection.js
MIT License
7.27k stars 639 forks source link

Incorrect typing of `idColumn` #2693

Open jackbonaguro opened 2 months ago

jackbonaguro commented 2 months ago

According to documentation, idColumn should be set to null in the event a table does not have an id column: https://vincit.github.io/objection.js/api/model/static-properties.html#static-idcolumn

But due to the typings, null is not a possible valid value for idColumn - only string | string[]: https://github.com/Vincit/objection.js/blob/d1e194a3ba58019a90579464459473e26668a4ab/typings/objection/index.d.ts#L1541

This causes an issue in my code on version 3.1.4. Doing either:

static idColumn = null;

or

static get idColumn() {
    return null;
}

Results in a compiler error:


  Types of property 'idColumn' are incompatible.
    Type 'null' is not assignable to type 'string | string[]```

Only by casting like `static idColumn = null as unknown as string;` can I work around the issue. Not setting idColumn causes runtime errors.
lehni commented 1 month ago

Thanks for pointing this out @jackbonaguro. I'm happy to accept a PR that fixes this.