Skip to content

Commit

Permalink
fix: update Poly.values to be more general with the key types
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkhogg committed Dec 2, 2024
1 parent 0785fc9 commit ebcc8b1
Show file tree
Hide file tree
Showing 11 changed files with 1,959 additions and 1,533 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.19
18.12
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ This file is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [2.5.3] - 2024-12-02

### Fixed:
- Updated types for `Poly.values` to prevent type errors on certain configurations.

## [2.5.2] - 2023-12-31

### Fixed:
Expand Down
2 changes: 1 addition & 1 deletion docs/polyethylene.poly.entries.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Returns a [PolySyncIterable](./polyethylene.polysynciterable.md) that yields the
**Signature:**

```typescript
function entries<K extends string | number | symbol, V>(obj: Record<K, V>): PolySyncIterable<[K, V]>;
function entries<K extends PropertyKey, V>(obj: Record<K, V>): PolySyncIterable<[K, V]>;
```

## Parameters
Expand Down
2 changes: 1 addition & 1 deletion docs/polyethylene.poly.keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Returns a [PolySyncIterable](./polyethylene.polysynciterable.md) that yields the
**Signature:**

```typescript
function keys<K extends string | number | symbol>(obj: Record<K, unknown>): PolySyncIterable<K>;
function keys<K extends PropertyKey>(obj: Record<K, unknown>): PolySyncIterable<K>;
```

## Parameters
Expand Down
4 changes: 2 additions & 2 deletions docs/polyethylene.poly.values.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Returns a [PolySyncIterable](./polyethylene.polysynciterable.md) that yields the
**Signature:**

```typescript
function values<V>(obj: Record<string | number | symbol, V>): PolySyncIterable<V>;
function values<V, K extends PropertyKey = PropertyKey>(obj: Record<K, V>): PolySyncIterable<V>;
```

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| obj | Record&lt;string \| number \| symbol, V&gt; | |
| obj | Record&lt;K, V&gt; | |

**Returns:**

Expand Down
4 changes: 2 additions & 2 deletions docs/polyethylene.polyasynciterable._symbol.asynciterator_.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Allows this class to work as a regular `AsyncIterable<T>`
**Signature:**

```typescript
[Symbol.asyncIterator](): AsyncIterator<T, any, undefined>;
[Symbol.asyncIterator](): AsyncIterator<T, any, any>;
```
**Returns:**

AsyncIterator&lt;T, any, undefined&gt;
AsyncIterator&lt;T, any, any&gt;

an async iterable that will yield the same elements as the iterable used to create this instance

53 changes: 42 additions & 11 deletions etc/polyethylene.api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,9 @@
"text": "function entries<K extends "
},
{
"kind": "Content",
"text": "string | number | symbol"
"kind": "Reference",
"text": "PropertyKey",
"canonicalReference": "!PropertyKey:type"
},
{
"kind": "Content",
Expand Down Expand Up @@ -1969,8 +1970,9 @@
"text": "function keys<K extends "
},
{
"kind": "Content",
"text": "string | number | symbol"
"kind": "Reference",
"text": "PropertyKey",
"canonicalReference": "!PropertyKey:type"
},
{
"kind": "Content",
Expand Down Expand Up @@ -2514,7 +2516,25 @@
"excerptTokens": [
{
"kind": "Content",
"text": "function values<V>(obj: "
"text": "function values<V, K extends "
},
{
"kind": "Reference",
"text": "PropertyKey",
"canonicalReference": "!PropertyKey:type"
},
{
"kind": "Content",
"text": " = "
},
{
"kind": "Reference",
"text": "PropertyKey",
"canonicalReference": "!PropertyKey:type"
},
{
"kind": "Content",
"text": ">(obj: "
},
{
"kind": "Reference",
Expand All @@ -2523,7 +2543,7 @@
},
{
"kind": "Content",
"text": "<string | number | symbol, V>"
"text": "<K, V>"
},
{
"kind": "Content",
Expand All @@ -2544,17 +2564,17 @@
}
],
"returnTypeTokenRange": {
"startIndex": 4,
"endIndex": 6
"startIndex": 8,
"endIndex": 10
},
"releaseTag": "Public",
"overloadIndex": 1,
"parameters": [
{
"parameterName": "obj",
"parameterTypeTokenRange": {
"startIndex": 1,
"endIndex": 3
"startIndex": 5,
"endIndex": 7
},
"isOptional": false
}
Expand All @@ -2570,6 +2590,17 @@
"startIndex": 0,
"endIndex": 0
}
},
{
"typeParameterName": "K",
"constraintTokenRange": {
"startIndex": 1,
"endIndex": 2
},
"defaultTypeTokenRange": {
"startIndex": 3,
"endIndex": 4
}
}
],
"name": "values"
Expand Down Expand Up @@ -2643,7 +2674,7 @@
},
{
"kind": "Content",
"text": "<T, any, undefined>"
"text": "<T, any, any>"
},
{
"kind": "Content",
Expand Down
8 changes: 4 additions & 4 deletions etc/polyethylene.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ namespace Poly {
function builder<T>(): AsyncIterableBuilder<T>;
function buildWith<T>(func: (builder: AsyncIterableBuilder<T>) => void): PolyAsyncIterable<T>;
function empty<T = never>(): PolySyncIterable<T>;
function entries<K extends string | number | symbol, V>(obj: Record<K, V>): PolySyncIterable<[K, V]>;
function entries<K extends PropertyKey, V>(obj: Record<K, V>): PolySyncIterable<[K, V]>;
function from<T>(iterableOrFactory: AsyncIterable<T> | AsyncIterableFactory<T>): PolyAsyncIterable<T>;
function from<T>(iterableOrFactory: Iterable<T> | IterableFactory<T>): PolySyncIterable<T>;
function from<T>(iterableOrFactory: Iterable<T> | IterableFactory<T> | AsyncIterable<T> | AsyncIterableFactory<T>): PolySyncIterable<T> | PolyAsyncIterable<T>;
type IterableFactory<T> = () => Iterable<T>;
function keys<K extends string | number | symbol>(obj: Record<K, unknown>): PolySyncIterable<K>;
function keys<K extends PropertyKey>(obj: Record<K, unknown>): PolySyncIterable<K>;
function range(to: number): PolySyncIterable<number>;
function range(from: number, to: number): PolySyncIterable<number>;
function range(from: number, to: number, step?: number): PolySyncIterable<number>;
function repeat<T>(value: T): PolySyncIterable<T>;
function syncFrom<T>(iterableOrFactory: Iterable<T> | IterableFactory<T>): PolySyncIterable<T>;
function syncIterate<T>(func: (lastValue: T | undefined) => T): PolySyncIterable<T>;
function syncIterate<T>(func: (lastValue: T) => T, initValue: T): PolySyncIterable<T>;
function values<V>(obj: Record<string | number | symbol, V>): PolySyncIterable<V>;
function values<V, K extends PropertyKey = PropertyKey>(obj: Record<K, V>): PolySyncIterable<V>;
}
export { Poly }
export default Poly;

// @public
export class PolyAsyncIterable<T> implements AsyncIterable<T> {
[Symbol.asyncIterator](): AsyncIterator<T, any, undefined>;
[Symbol.asyncIterator](): AsyncIterator<T, any, any>;
// @internal
constructor(iterable: AsyncIterable<T>);
append<U>(other: Iterable<U> | AsyncIterable<U>): PolyAsyncIterable<T | U>;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "polyethylene",
"version": "2.5.2",
"version": "2.5.3",
"description": "Functional programming for iterables and async iterables",
"author": "Daniel Escoz <[email protected]>",
"license": "MIT",
Expand Down Expand Up @@ -44,6 +44,6 @@
"mocha": "^9.2.2",
"nyc": "^15.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
"typescript": "^5.7.2"
}
}
Loading

0 comments on commit ebcc8b1

Please sign in to comment.