nestjs-paginate
nestjs-paginate copied to clipboard
PaginateConfig has string default type for some attributes even it's a generic interface
While using the PaginateConfig
interface, when trying to provide values to filterableColumns
or select
attributes, I cannot get hints about real attributes in the entity, even that PaginateConfig has a required generic type.
For example, having this:
const config: PaginateConfig<MeetingEntity> = {
filterableColumns: {
name: true,
// Cursor placed here
},
};
And placed just below the name: true
, when pressing CTRL+I in VSCode to get hints about other attributes in MeetingEntity
, I cannot get the attributes. The definition of PaginateConfig is as follows:
export interface PaginateConfig<T> {
relations?: FindOptionsRelations<T> | RelationColumn<T>[] | FindOptionsRelationByString
sortableColumns: Column<T>[]
nullSort?: 'first' | 'last'
searchableColumns?: Column<T>[]
select?: Column<T>[] | string[]
maxLimit?: number
defaultSortBy?: SortBy<T>
defaultLimit?: number
where?: FindOptionsWhere<T> | FindOptionsWhere<T>[]
filterableColumns?: {
[key in Column<T> | string]?: (FilterOperator | FilterSuffix)[] | true
}
loadEagerRelations?: boolean
withDeleted?: boolean
paginationType?: PaginationType
relativePath?: boolean
origin?: string
ignoreSearchByInQueryParam?: boolean
ignoreSelectInQueryParam?: boolean
}
https://github.com/ppetzold/nestjs-paginate/blob/master/src/paginate.ts#L68
To solve the problem, the | string
in both attributes should be removed, as there is no valid way PaginateConfig does not have a type provided and defaulting to string breaks previous Column<T>
typing. This also bypasses static analysis for non existing attributes.
I have tried to create a PR with these changes but I'm not allowed to push to the repository.