eclipsesource / eclipsesource/tabris-js

Single parameter type of WidgetCollection.filter() callback function gets inferred as `any`

Open
#1,965 0 comments 0 reactions 0 assignees View on GitHub
TypeScript/JSX
Dominant language
JavaScript
Stars
1.4k
Forks
171
PR merge metrics
No merged PRs in 30d

Description

### Problem description

When using a filter function with a single parameter, this single parameter is always of type `any`.

The issue likely stems from the selector function using an union type including both

```ts
export type SelectorFunction = (widget: Candidate, index: number, collection: WidgetCollection) => boolean;
```

and

```ts
export type SFC = (attributes: object|null, children: any[]) => T;
```

### Expected behavior

The type of the single parameter of a filter function should be properly inferred. Using a single parameter in a filter function is the most common use case.

### Environment

Tabris.js version: 3.2.1

### Code snippet

```javascript
// 'widget' has `any` type:
new WidgetCollection().filter(widget => true);

// 'widget' has `Button` type:
new WidgetCollection().filter((widget, index, collection) => true);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.