Open mykhalov opened 2 years ago
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?
We bounced the idea back and forth a bit, and generally think this is more likely to cause more breakages than it cures 👍🏻
cause more breakages than it cures
What breakages for example?
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.
Sounds good to me but I wonder what TS team thinks about the suggestion, maybe @DanielRosenwasser?
I just ran into this issue. Adding /** @deprecated */
seems like a good and simple fix.
What do you think, @DanielRosenwasser?
@sandersn Do you some context around https://github.com/microsoft/TypeScript-DOM-lib-generator/issues/1162#issuecomment-933853993 ?
E.g. trying to call
AbortSignal
with new throwsIllegal constructor
error.This is not currently handled by the declaration: