Skip to content

WeakMapConstructor and WeakSetConstructor should be able to take undefined and null #54641

@AlexErrant

Description

@AlexErrant

lib Update Request

Configuration Check

My compilation target is ES2015 and my lib is es2021.

Missing / Incorrect Definition

The es2015.iterable type definitions for WeakMap and WeakSet's ctors are missing undefined and null, contrary to the weakmap spec and the weakset spec:

  1. If iterable is either undefined or null, return map.
  2. If iterable is either undefined or null, return set.

interface WeakMapConstructor {
new <K extends WeakKey, V>(iterable: Iterable<readonly [K, V]>): WeakMap<K, V>;
}

interface WeakSetConstructor {
new <T extends WeakKey = WeakKey>(iterable: Iterable<T>): WeakSet<T>;
}

The (non-weak) Map ctor was made optional/nullable in this PR from 2021 - I assume that WeakMap/WeakSet was missed as an oversight.

I began to address this issue in this branch, but the PR template required an issue so here I am :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Not a DefectThis behavior is one of several equally-correct options

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions