1 | # `no-misused-new`
|
2 |
|
3 | Enforce valid definition of `new` and `constructor`.
|
4 |
|
5 | Warns on apparent attempts to define constructors for interfaces or `new` for classes.
|
6 |
|
7 | ## Rule Details
|
8 |
|
9 | Examples of code for this rule:
|
10 |
|
11 |
|
12 |
|
13 | ### ❌ Incorrect
|
14 |
|
15 | ```ts
|
16 | class C {
|
17 | new(): C;
|
18 | }
|
19 |
|
20 | interface I {
|
21 | new (): I;
|
22 | constructor(): void;
|
23 | }
|
24 | ```
|
25 |
|
26 | ### ✅ Correct
|
27 |
|
28 | ```ts
|
29 | class C {
|
30 | constructor() {}
|
31 | }
|
32 | interface I {
|
33 | new (): C;
|
34 | }
|
35 | ```
|
36 |
|
37 | ## Options
|
38 |
|
39 | ```jsonc
|
40 | // .eslintrc.json
|
41 | {
|
42 | "rules": {
|
43 | "@typescript-eslint/no-misused-new": "error"
|
44 | }
|
45 | }
|
46 | ```
|
47 |
|
48 | This rule is not configurable.
|
49 |
|
50 | ## Related To
|
51 |
|
52 | - TSLint: [no-misused-new](https://palantir.github.io/tslint/rules/no-misused-new/)
|
53 |
|
54 | ## Attributes
|
55 |
|
56 | - Configs:
|
57 | - [x] ✅ Recommended
|
58 | - [x] 🔒 Strict
|
59 | - [ ] 🔧 Fixable
|
60 | - [ ] 💭 Requires type information
|