Skip to content

Commit

Permalink
update IDE type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mskocik committed Jan 6, 2025
1 parent 1914443 commit 1193988
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/lib/utils/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ export function getFilterProps(object) {
* @param {?string} inputValue
* @param {?Set} excludeSelected
* @param {ComponentConfig} config
* @param {SearchProps|null} searchProps
* @param {SearchProps} searchProps
* @returns {object[]}
*/
export function filterList(options, inputValue, excludeSelected, config, searchProps) {
export function filterList(options, inputValue, excludeSelected, config, searchProps = {}) {
if (!searchProps.keepSelectionInList && excludeSelected) {
options = options
.filter(opt => !excludeSelected.has(opt[config.valueField]))
Expand Down Expand Up @@ -219,12 +219,14 @@ export function fieldInit(type, options, groupItemsField) {
const isValue = type === 'value';
let val = isValue ? 'value' : 'text'; // selectize style defaults
if (options && options.length) {
// @ts-ignore
const firstItem = options[0][groupItemsField] ? options[0][groupItemsField][0] : options[0];
if (!firstItem || typeof firstItem === 'string') return val;
const autoAddItem = isValue ? 0 : 1;
const guessList = isValue
? ['id', 'value', 'ID']
: ['name', 'title', 'label'];
// @ts-ignore
val = Object.keys(firstItem).filter(prop => guessList.includes(prop))
.concat([Object.keys(firstItem)[autoAddItem]]) // auto add field (used as fallback) if empty list is returned
.shift();
Expand Down
5 changes: 3 additions & 2 deletions src/lib/utils/sifter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @constructor
* @param {array|object} items
* @param {object} items
* @param {object} [settings]
*/
var Sifter = function(items, settings) {
this.items = items;
Expand Down Expand Up @@ -112,7 +112,7 @@ Sifter.prototype.iterator = function(object, callback) {
* If an item is not a match, 0 will be returned by the function.
*
* @param {object|string} search
* @param {object} options (optional)
* @param {object} [options]
* @returns {function}
*/
Sifter.prototype.getScoreFunction = function(search, options) {
Expand Down Expand Up @@ -425,6 +425,7 @@ var getattr = function(obj, name, nesting) {
if (!obj || !name) return;
if (!nesting) return obj[name];
var names = name.split(".");
// @ts-ignore
while(names.length && (obj = obj[names.shift()]));
return obj;
};
Expand Down

0 comments on commit 1193988

Please sign in to comment.