You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type definition for attr (without arguments) is the following:
/**
* Method for getting all attributes and their values of the first element in
* the matched set.
*
* @category Attributes
* @example
*
* ```js
* $('ul').attr();
* //=> { id: 'fruits' }
* ```
*
* @returns The attribute's values.
* @see {@link https://api.jquery.com/attr/}
*/
export declare function attr<T extends Node>(this: Cheerio<T>): Record<string, string>;
However, attr can also return undefined if called on a missing element. For example:
Welcome to Node.js v12.22.3.
Type ".help" for more information.
> const cheerio = require('cheerio')
undefined
> const $ = cheerio.load("<body></body>", { xml: true }, false)
undefined
> $("meta").attr()
undefined
This is unsafe and can cause unexpected runtime errors. The type signature should probably be:
Version: v1.0.0-rc.10
The type definition for
attr
(without arguments) is the following:However,
attr
can also return undefined if called on a missing element. For example:This is unsafe and can cause unexpected runtime errors. The type signature should probably be:
I'll see if I can have a dig and find out why the types are generated that way.
Thanks!
The text was updated successfully, but these errors were encountered: