question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not all interfaces should be marked as constructable

See original GitHub issue

E.g. trying to call AbortSignal with new throws Illegal constructor error.

> new AbortSignal()
  Uncaught TypeError: Illegal constructor.

This is not currently handled by the declaration:

declare var AbortSignal: {
    prototype: AbortSignal;
    new(): AbortSignal;
};

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
saschanazcommented, Oct 3, 2021

This is because instanceof check requires a constructor member. But never seemingly works:

interface Foo {}

declare var Foo: {
    prototype: Foo;
    new(): never;
};

let foo = {} as Foo;
if (foo instanceof Foo) {
  foo // $Foo
}

@orta does new(): never make sense to fix this?

1reaction
aloisklinkcommented, Sep 4, 2022

This also affects NodeList (which could have prevented a bug: https://github.com/mermaid-js/mermaid/pull/3396)

Maybe it’s worth putting in a /** @deprecated */ JSDoc tag to constructors that throw Illegal constructor, so some tools (like ESLint/VS Code) will warn about using them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot use new with expression typescript - Stack Overflow
The problem is that the compiler treats the contextClass variable as an instance of AudioContext while in fact it's merely a constructor ...
Read more >
Generic class decorator does not typecheck #23049 - GitHub
Basically what I'm trying to achieve is that the extended class is "class extends ctor implements Interface". that is the instance side of...
Read more >
How To Use Classes in TypeScript | DigitalOcean
Interfaces are useful to specify a set of behaviors that all implementations of that interface must possess. Interfaces are created by using ...
Read more >
Interface with NSRR and Flaggers | FTA
Availability of eight flagmen was shown in RBT contract, but the detail of how many and the timing of the flaggers were not...
Read more >
A simple guide to “interface” data type in TypeScript - Medium
JavaScript object keys in almost all the cases are strings and their values ... Not only the shape of a plain object, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found