Skip to content

[Web API type definition issue] lib.dom options parameter for MutationObserver#observe should not be optional #2566

Description

@trusktr

Summary

Not passing options, or passing options without minimum requirements, is an error (type error at runtime)

Expected vs. Actual Behavior

Expected:

Calling new MutationObserver(fn).observe(el) without a second options argument should show a type error because options are required.

Actual:

There is no type error. We discover the error at runtime.

Playground Link

https://www.typescriptlang.org/play/?#code/MYewdgzgLgBAtiGBeGYCmB3GBZArlAQygEtwB5AIwjQCcA3WgCkYEpkA+GAbwF8WAofgHohMAAJQIAWjQAPAA5pgUGTRogaMKAAs0MaqDA0AJjAI0A5rjhowsYhBg00AR1zFnpgsFAniYCy1ECEVgADoYADkQWHkCCAh-QOJYHXUMRwIYABUAT0UAUTUNfgQwkCpaBkZjEGBrWygwihBjXJYgA

Browser Support

  • This API is supported in at least two major browser engines (not two Chromium-based browsers).

Have Tried The Latest Releases

  • This issue applies to the latest release of TypeScript.
  • This issue applies to the latest release of @types/web.

Additional Context

From MDN docs:

An object providing options that describe which DOM mutations should be reported to mutationObserver's callback. At a minimum, one of childList, attributes, and/or characterData must be true when you call observe(). Otherwise, a TypeError exception will be thrown.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions