persona-community-5/.pnpm-store/v3/files/e5/a0119ab2ef360da0fe06a14de9eaccb2b1c73a0a40a464ed04efb0959e66b279f3a798c0ab470cb8c107dbed0167ef641dce86113bfee8adf0958ec3bdaa68
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

54 lines
1.4 KiB
Plaintext

---
description: 'Enforce valid definition of `new` and `constructor`.'
---
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
> 🛑 This file is source code, not the primary documentation location! 🛑
>
> See **https://typescript-eslint.io/rules/no-misused-new** for documentation.
JavaScript classes may define a `constructor` method that runs when a class instance is newly created.
TypeScript allows interfaces that describe a static class object to define a `new()` method (though this is rarely used in real world code).
Developers new to JavaScript classes and/or TypeScript interfaces may sometimes confuse when to use `constructor` or `new`.
This rule reports when a class defines a method named `new` or an interface defines a method named `constructor`.
## Examples
<Tabs>
<TabItem value="❌ Incorrect">
```ts
declare class C {
new(): C;
}
interface I {
new (): I;
constructor(): void;
}
```
</TabItem>
<TabItem value="✅ Correct">
```ts
declare class C {
constructor();
}
interface I {
new (): C;
}
```
</TabItem>
</Tabs>
## When Not To Use It
If you intentionally want a class with a `new` method, and you're confident nobody working in your code will mistake it with a constructor, you might not want this rule.
You might consider using [ESLint disable comments](https://eslint.org/docs/latest/use/configure/rules#using-configuration-comments-1) for those specific situations instead of completely disabling this rule.