hasQuery
guards
Source Code | DocumentationSee also: utility-types/required-query
Type guard to check if the query property of Params is present and non-nullable.
ts
import { hasQuery } from 'feathers-utils/guards';Example
ts
import { hasQuery } from 'feathers-utils/guards'
function example(params: Params) {
// `params.query` is optional and can be undefined at this point
if (!hasQuery(params)) {
return;
}
// TypeScript now knows that params.query is present and non-nullable
// You can safely access params.query here without additional checks
}Type declaration
Show Type Declarations
ts
/**
* Type guard to check if the `query` property of `Params` is present and non-nullable.
*
* @param params - The `Params` object to check.
* @returns `true` if `params.query` is present and non-nullable, otherwise `false`.
*
* @see https://utils.feathersjs.com/guards/has-query.html
*
* @example
* ```ts
*
*
* function example(params: Params) {
* // `params.query` is optional and can be undefined at this point
* if (!hasQuery(params)) {
* return;
* }
*
* // TypeScript now knows that params.query is present and non-nullable
* // You can safely access params.query here without additional checks
* }
* ```
*/
export declare function hasQuery<P extends Params>(
params: P,
): params is RequiredQuery<P>| Argument | Type | Description |
|---|---|---|
| params | P |
