Skip to content

Update lib.dom.d.ts: MutationObserverInit.attributeFilter can accept an iterator #55990

Open

Description

@trusktr

⚙ Compilation target

n/a

⚙ Library

lib.dom

Missing / Incorrect Definition

MutationObserverInit

Sample Code

The following code works in Chredge, Firefox, and Safari:

const obs = new MutationObserver((records) => {
    console.log(...records)
})

const s = new Set(['foo', 'bar'])

obs.observe(document.body, {
  attributeFilter: s.keys() // <--------- HERE
})

document.body.setAttribute('foo', 'foo')
document.body.removeAttribute('foo')
document.body.setAttribute('bar', 'bar')
document.body.removeAttribute('bar')

Edge screenshot:

Screenshot 2023-10-04 at 6 36 01 PM

Documentation Link

https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe#parameters

WIP Pull Request

Activity

  1. RyanCavanaugh commented on Sep 19, 2026

    @RyanCavanaugh
    Member

    MutationObserverInit.attributeFilter is currently declared as string[], but the platform accepts an iterable of strings. In Edge 153.0.4234.32, Set<string>.keys() is accepted and filters both requested attributes. TypeScript 5.2.2 and current native 7.1.0-dev.20260918.1 both report TS2740 because the iterator is not assignable to string[].

    This concise code demonstrates the mismatch:

    const names = new Set<string>();
    
    // Expected: MutationObserverInit.attributeFilter accepts a Set<string>.keys() iterator.
    // Actual: TypeScript rejects the iterator with TS2740.
    const options: MutationObserverInit = { attributeFilter: names.keys() };

    The DOM specification defines attributeFilter as a sequence of DOM strings, whose Web IDL conversion accepts iterables. The declaration should model that accepted iterable input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions