UNPKG

792 BMarkdownView Raw
1# `no-misused-new`
2
3Enforce valid definition of `new` and `constructor`.
4
5Warns on apparent attempts to define constructors for interfaces or `new` for classes.
6
7## Rule Details
8
9Examples of code for this rule:
10
11<!--tabs-->
12
13### ❌ Incorrect
14
15```ts
16class C {
17 new(): C;
18}
19
20interface I {
21 new (): I;
22 constructor(): void;
23}
24```
25
26### ✅ Correct
27
28```ts
29class C {
30 constructor() {}
31}
32interface 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
48This 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