Skip to content

Commit

Permalink
improve typing for static .from() method
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Jul 10, 2024
1 parent 21357a3 commit 6875104
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Changelog


## [4.5.0](https://github.com/supercharge/arrays/compare/v4.4.0...v4.5.0) - 2024-07-xx

### Updated
- static `from`: improve typing for returned instance type. This allows subclassing the `Arr` class and receiving the correct class instance type


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

### 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

Expand Down
6 changes: 3 additions & 3 deletions src/arr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ export class Arr<T> {
}

/**
* Creates an array from an iterable object.
* Creates an Arr instance from iterable values.
*/
static from<T> (...values: Values<T>): Arr<T> {
return new this<T>(...values)
static from<T, Ctor extends Arr<T>> (this: new (...values: Values<T>) => Ctor, ...values: Values<T>): Ctor {
return new this(...values)
}

/**
Expand Down

0 comments on commit 6875104

Please sign in to comment.