Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions typings/objection/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1442,11 +1442,11 @@ declare namespace Objection {
QueryBuilder: typeof QueryBuilder;

tableName: string;
idColumn: string | string[];
idColumn: string | string[] | readonly string[] | never;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does never achieve here?

Copy link
Author

@salisbury-espinosa salisbury-espinosa May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lehni

the table model may not have any column id at all (not an empty array - but simply a method, for example, always throw out an exception)

static get idColumn(): never {
        throw new Error(`undefined id for ..some.. table`);
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@geeksilva97 geeksilva97 May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be the purpose of an idColumn gett that throws an exception?

Copy link
Author

@salisbury-espinosa salisbury-espinosa May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goal - if the table does not have id - it cannot be used in runtime.
this should generate an exception, and not allow further compilation of SQL code.
and using never as a return value for the idColumn function will allow wrapping the code at the static compilation level, any use will generate a compile time error.
details here #2693 (comment)

the very reference to idColumn, when it does not exist, is a code logic error!

and already now if you allow null then there will be an error during the assembly of certain queries!
this will introduce regression into the code base!

jsonSchema: JSONSchema;
relationMappings: RelationMappings | RelationMappingsThunk;
modelPaths: string[];
jsonAttributes: string[];
jsonAttributes: string[] | readonly string[];
virtualAttributes: string[];
uidProp: string;
uidRefProp: string;
Expand Down Expand Up @@ -1551,11 +1551,11 @@ declare namespace Objection {
static QueryBuilder: typeof QueryBuilder;

static tableName: string;
static idColumn: string | string[];
static idColumn: string | string[] | readonly string[] | never;
static jsonSchema: JSONSchema;
static relationMappings: RelationMappings | RelationMappingsThunk;
static modelPaths: string[];
static jsonAttributes: string[];
static jsonAttributes: string[] | readonly string[];
static virtualAttributes: string[];
static uidProp: string;
static uidRefProp: string;
Expand Down