Skip to content

Commit

Permalink
refined return type for truthy values in compact method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Feb 20, 2024
1 parent d14902e commit b78b00f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
# Changelog


## [4.4.0](https://github.com/supercharge/arrays/compare/v4.3.0...v4.4.0) - 2024-02-xx

### Added
- `compact`: refined return type for truthy values

### Updated
- `sort`: make the `comparator` parameter optional

### Updated
- bump dependencies
- bump dependencies in GitHub Actions testing workflow


## [4.3.0](https://github.com/supercharge/arrays/compare/v4.2.0...v4.3.0) - 2023-03-12

### Added
Expand Down
8 changes: 6 additions & 2 deletions src/arr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ type Values<T> = Array<T | Iterable<T> | undefined | null>

type Predicate<T> = ((item: T, index: number, array: Arr<T>) => unknown)

type Truthy<T> = T extends null | undefined | false | '' | 0
? never
: T

export class Arr<T> {
/**
* The values to work with.
Expand Down Expand Up @@ -103,8 +107,8 @@ export class Arr<T> {
* Removes all falsy values from the given `array`. Falsy values
* are `null`, `undefined`, `''`, `false`, `0`, `-0`, `0n`, `NaN`.
*/
compact (): Arr<T> {
return this.filter(Boolean)
compact (): Arr<Truthy<T>> {
return this.filter(Boolean) as Arr<Truthy<T>>
}

/**
Expand Down

0 comments on commit b78b00f

Please sign in to comment.