src/content/docs/linter/rules/no-misleading-instantiator.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="TypeScript and TSX" icon="seti:typescript"> ## Summary - Rule available since: `v1.3.0` - Diagnostic Category: [`lint/suspicious/noMisleadingInstantiator`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**error**](/reference/diagnostics#error). - Sources: - Same as [`@typescript-eslint/no-misused-new`](https://typescript-eslint.io/rules/no-misused-new){
"linter": {
"rules": {
"suspicious": {
"noMisleadingInstantiator": "error"
}
}
}
}
Enforce proper usage of new and constructor.
In JavaScript, classes utilize the constructor method to initialize a new instance. On the other hand, TypeScript interfaces can describe a class type with a new() method signature, though this pattern is not commonly seen in real-world code. Developers, especially those new to JavaScript or TypeScript, might occasionally confuse the use of constructor with new.
This rule triggers warnings in the following scenarios:
new.constructor or new that returns the interface type.constructor method.You should not use this rule if you intentionally want a class with a new method, and you're confident nobody working in your code will mistake it with an constructor.
interface I {
new (): I;
constructor(): void;
}
class C {
new(): C;
}
declare class C {
constructor();
}
interface I {
new (): C;
}