Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot extend XMLHttpRequest when target is ES5 #57945

Closed
guilhermesimoes opened this issue Mar 26, 2024 · 2 comments
Closed

Cannot extend XMLHttpRequest when target is ES5 #57945

guilhermesimoes opened this issue Mar 26, 2024 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@guilhermesimoes
Copy link

guilhermesimoes commented Mar 26, 2024

🔎 Search Terms

Uncaught TypeError, Failed to construct, DOM object constructor cannot be called as a function

🕗 Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/play?target=1&ssl=1&ssc=32&pln=1&pc=46#code/MYGwhgzhAECyCeANWAZAEgFwwBwEoFMBHAV3wg2nwA8N8A7AExmXSzyNPOgG8AoaaNgBOASwBuYWtDAAuaHWIBbAEb4hAbl79owAPZ1yQ4sAy6hACgCUPbQIjFsaq5tvQMACxEQAdGGgBeaABGTQEAX14I3gh8EAAzbxZMHAISMgpAhCS2VM4MFz0DCip3IQD5fAB3aGyUjnTnIA

💻 Code

class MyXMLHttpRequest extends XMLHttpRequest {
  private a: number;

  constructor() {
    super();

    this.a = 1;
  }
}

self.XMLHttpRequest = MyXMLHttpRequest;

const xhr = new XMLHttpRequest();

🙁 Actual behavior

When transpiling to ES5, trying to run the resulting code throws the following error:

Uncaught TypeError: Failed to construct 'XMLHttpRequest': Please use the 'new' operator, this DOM object constructor cannot be called as a function

This is due to the generated code _super.call(this).

🙂 Expected behavior

The ES5 transpile output should behave similarly to the ES2015 transpile output. At least it shouldn't crash.

Additional information about the issue

Related to #12949
Related to #15397

@nmain
Copy link

nmain commented Mar 26, 2024

Related to #15397

Does this add any new information or is it just a duplicate of that?

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Apr 11, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants