Skip to content

Conversation

salisbury-espinosa
Copy link

@salisbury-espinosa salisbury-espinosa commented Feb 26, 2025

fixes #2745

@salisbury-espinosa salisbury-espinosa changed the title Update index.d.ts Fix idColumn type Feb 26, 2025
@salisbury-espinosa salisbury-espinosa changed the title Fix idColumn type Fix idColumn + jsonAttributes type Feb 26, 2025
@@ -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!

This was referenced May 27, 2025
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

Successfully merging this pull request may close these issues.

impossible to make idColumn/jsonAttributes **readonly**
3 participants