Skip to content

Commit

Permalink
fix(toMap): fix return type of keySelector (#365)
Browse files Browse the repository at this point in the history
change return type of keySelector from TElement to TKey, since keySelector returns keys, not elements

Closes: #364
  • Loading branch information
berndfuhrmann authored May 8, 2024
1 parent ff1cef0 commit eab2f10
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/add/asynciterable-operators/tomap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toMap, ToMapOptions } from '../../asynciterable/tomap';

export async function toMapProto<TSource, TKey, TElement = TSource>(
this: AsyncIterable<TSource>,
options: ToMapOptions<TSource, TElement>
options: ToMapOptions<TSource, TKey, TElement>
): Promise<Map<TKey, TElement | TSource>> {
return toMap(this, options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/add/iterable-operators/tomap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { toMap, ToMapOptions } from '../../iterable/tomap';

export function toMapProto<TSource, TKey, TElement = TSource>(
this: IterableX<TSource>,
options: ToMapOptions<TSource, TElement>
options: ToMapOptions<TSource, TKey, TElement>
): Map<TKey, TElement | TSource> {
return toMap(this, options);
}
Expand Down
6 changes: 3 additions & 3 deletions src/asynciterable/tomap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { throwIfAborted } from '../aborterror';
* @template TElement
* @ignore
*/
export interface ToMapOptions<TSource, TElement> {
export interface ToMapOptions<TSource, TKey, TElement> {
/**
* The selector to get the key for the map.
*
* @memberof ToMapOptions
*/
keySelector: (item: TSource, signal?: AbortSignal) => TElement | Promise<TElement>;
keySelector: (item: TSource, signal?: AbortSignal) => TKey | Promise<TKey>;
/**
* The selector used to get the element for the Map.
*
Expand Down Expand Up @@ -44,7 +44,7 @@ export interface ToMapOptions<TSource, TElement> {
*/
export async function toMap<TSource, TKey, TElement = TSource>(
source: AsyncIterable<TSource>,
options: ToMapOptions<TSource, TElement>
options: ToMapOptions<TSource, TKey, TElement>
): Promise<Map<TKey, TElement | TSource>> {
const {
['signal']: signal,
Expand Down
6 changes: 3 additions & 3 deletions src/iterable/tomap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import { identity } from '../util/identity';
* @template TElement
* @ignore
*/
export interface ToMapOptions<TSource, TElement> {
export interface ToMapOptions<TSource, TKey, TElement> {
/**
* The selector to get the key for the map.
*
* @memberof ToMapOptions
*/
keySelector: (item: TSource) => TElement;
keySelector: (item: TSource) => TKey;
/**
* The selector used to get the element for the Map.
*
Expand All @@ -35,7 +35,7 @@ export interface ToMapOptions<TSource, TElement> {
*/
export function toMap<TSource, TKey, TElement = TSource>(
source: Iterable<TSource>,
options: ToMapOptions<TSource, TElement>
options: ToMapOptions<TSource, TKey, TElement>
): Map<TKey, TElement | TSource> {
const {
['elementSelector']: elementSelector = identity as any,
Expand Down

0 comments on commit eab2f10

Please sign in to comment.