also looking at this
refactor(types): stop publishing `any` across the query builder's surface
#1117
13 files
+359
-110
| @@ -372,7 +372,9 @@ export class BrowserQueryBuilder<T = any> { | ||
| 372 | 372 | /** |
| 373 | 373 | * Add a where clause |
| 374 | 374 | */ |
| 375 | where(column: string, operatorOrValue: WhereOperator | any, value?: any): this { | |
| 375 | where(column: string, value: unknown): this | |
| 376 | where(column: string, operator: WhereOperator, value: unknown): this | |
| 377 | where(column: string, operatorOrValue: unknown, value?: unknown): this { | |
| 376 | 378 | if (value === undefined) { |
| 377 | 379 | // where('column', value) shorthand for equality |
| 378 | 380 | this.state.wheres.push({ |
| @@ -397,7 +399,9 @@ export class BrowserQueryBuilder<T = any> { | ||
| 397 | 399 | /** |
| 398 | 400 | * Add an OR where clause |
| 399 | 401 | */ |
| 400 | orWhere(column: string, operatorOrValue: WhereOperator | any, value?: any): this { | |
| 402 | orWhere(column: string, value: unknown): this | |
| 403 | orWhere(column: string, operator: WhereOperator, value: unknown): this | |
| 404 | orWhere(column: string, operatorOrValue: unknown, value?: unknown): this { | |
| 401 | 405 | if (value === undefined) { |
| 402 | 406 | this.state.wheres.push({ |
| 403 | 407 | column, |
| @@ -420,8 +424,15 @@ export class BrowserQueryBuilder<T = any> { | ||
| 420 | 424 | /** |
| 421 | 425 | * Add an AND where clause (alias for where) |
| 422 | 426 | */ |
| 423 | andWhere(column: string, operatorOrValue: WhereOperator | any, value?: any): this { | |
| 424 | return this.where(column, operatorOrValue, value) | |
| 427 | andWhere(column: string, value: unknown): this | |
| 428 | andWhere(column: string, operator: WhereOperator, value: unknown): this | |
| 429 | andWhere(column: string, operatorOrValue: unknown, value?: unknown): this { | |
| 430 | // Two args means the second is a value; three means it is an operator - | |
| 431 | // which is exactly what the overloads above declare, so the dispatch is | |
| 432 | // split here rather than passing an unknown into the operator position. | |
| 433 | return value === undefined | |
| 434 | ? this.where(column, operatorOrValue) | |
| 435 | : this.where(column, operatorOrValue as WhereOperator, value) | |
| 425 | 436 | } |
| 426 | 437 | |
| 427 | 438 | /** |
| @@ -441,14 +452,14 @@ export class BrowserQueryBuilder<T = any> { | ||
| 441 | 452 | /** |
| 442 | 453 | * Where column is in array |
| 443 | 454 | */ |
| 444 | whereIn(column: string, values: any[]): this { | |
| 455 | whereIn(column: string, values: readonly unknown[]): this { | |
| 445 | 456 | return this.where(column, 'in', values) |
| 446 | 457 | } |
| 447 | 458 | |
| 448 | 459 | /** |
| 449 | 460 | * Where column is not in array |
| 450 | 461 | */ |
| 451 | whereNotIn(column: string, values: any[]): this { | |
| 462 | whereNotIn(column: string, values: readonly unknown[]): this { | |
| 452 | 463 | return this.where(column, 'not in', values) |
| 453 | 464 | } |
| 454 | 465 | |