Skip to content

Possible breaking change: assigning array to 1-tuple #42504

Closed
@amcasey

Description

@amcasey

Bug Report

🔎 Search Terms

dom, tuple, assignability

🕗 Version & Regression Information

Repros in 4.2 Beta and nightly

  • This changed between versions 4.1.3 and 4.2 beta

Important caveat: The code was originally building against 4.1 and had polyfills for types that are in lib.dom.d.ts in 4.2.

⏯ Playground Link

TS 4.1.3 with polyfills: Playground

TS 4.2 beta with re-declaration of lib.dom.d.ts interface: Playground

💻 Code

interface ResizeObserverCallback {
  (entries: ResizeObserverEntry[], observer: ResizeObserver): void;
}

const resizeObserver = new ResizeObserver(([entry]) => {
  entry
});

🙁 Actual behavior

Argument of type '([entry]: [any]) => void' is not assignable to parameter of type 'ResizeObserverCallback'.
  Types of parameters '__0' and 'entries' are incompatible.
    Type 'ResizeObserverEntry[]' is not assignable to type '[any]'.
      Target requires 1 element(s) but source may have fewer.(2345)

🙂 Expected behavior

The fact that the repro depends on re-declaring a dom interface is suspicious, but the re-declaration appears to be identical, so it's not obvious to me why this error would be produced.

Also, note that the (as a result of sensible variance reasons), the lambda parameter is listed before the callback parameter on line 2 of the error and the types are in the opposite order on line 3 of the error. I found this confusing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions