Skip to content

Commit

Permalink
types(collection): simplify ambient constructor declaration (#10549)
Browse files Browse the repository at this point in the history
- deduplicates constructor definition
- removes Collection's "internal" JSDoc description block
- removes unnecessary `extends` clause

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Renegade334 and kodiakhq[bot] authored Nov 7, 2024
1 parent ea04245 commit c973106
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions packages/collection/src/collection.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
/* eslint-disable no-param-reassign */
/**
* @internal
*/
export interface CollectionConstructor {
new (): Collection<unknown, unknown>;
new <Key, Value>(entries?: readonly (readonly [Key, Value])[] | null): Collection<Key, Value>;
new <Key, Value>(iterable: Iterable<readonly [Key, Value]>): Collection<Key, Value>;
readonly prototype: Collection<unknown, unknown>;
readonly [Symbol.species]: CollectionConstructor;
}

/**
* Represents an immutable version of a collection
Expand All @@ -19,13 +9,13 @@ export type ReadonlyCollection<Key, Value> = Omit<
> &
ReadonlyMap<Key, Value>;

/**
* Separate interface for the constructor so that emitted js does not have a constructor that overwrites itself
*
* @internal
*/
export interface Collection<Key, Value> extends Map<Key, Value> {
constructor: CollectionConstructor;
export interface Collection<Key, Value> {
/**
* Ambient declaration to allow `this.constructor[@@species]` in class methods.
*
* @internal
*/
constructor: typeof Collection & { readonly [Symbol.species]: typeof Collection };
}

/**
Expand Down

0 comments on commit c973106

Please sign in to comment.