Skip to content

Make standard library types more polyfills‑friendly #63069

@slowcheetah

Description

@slowcheetah

A significant number of ECMAScript / web standards features that have recently standardized (like Iterator.concat) are still missing from the TypeScript standard library. There are ECMAScript proposals (like Iterator.zip) that are supported by modern browsers but still lack corresponding type definitions. Finally, many projects intentionally target older TypeScript versions with old standard library types.

I am working on types for the core-js polyfill library, which is used on most websites, so it makes a lot of sense to add type definitions for it. While doing this work, I have encountered some significant issues:

  • Some DOM types, for example URL, are declared as ambient variable declarations with type literals in lib.dom.d.ts. This approach does not allow declaration merging. Possible solution: define them via interfaces (like in ECMAScript types) to allow declaration merging.

  • The use of getters/setters. For example, ArrayBuffer defines the detached property via a getter. This makes it impossible to create a compatible polyfill type for different targets. Similar issues often cause conflicts between different type libraries. In most similar cases, accessors are declared as readonly properties, and this does not cause any problems.

If there were some mechanism for conditional type usage, it could make the standard types more polyfills‑friendly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions