--- source: crates/biome_js_analyze/tests/spec_tests.rs expression: invalid.ts --- # Input ```ts interface I { new (): I; } interface I { constructor(): void; } // Works for generic type. interface G { new (): G; } type T = { constructor(): void; }; class C { new(): C; } class C { new(): this; } declare abstract class C { new(): C; } interface I { constructor(): ''; } interface I { new(): this; } ``` # Diagnostics ``` invalid.ts:2:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the new method in interfaces. 1 │ interface I { > 2 │ new (): I; │ ^^^^^^^^^^ 3 │ } 4 │ i new in an interface suggests it's instantiable, which is incorrect. The returned type should different from the constructor's type. ``` ``` invalid.ts:6:2 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the constructor method in interfaces. 5 │ interface I { > 6 │ constructor(): void; │ ^^^^^^^^^^^^^^^^^^^^ 7 │ } 8 │ i Interfaces define a contract, not an implementation. Thus, including a constructoris not appropriate. ``` ``` invalid.ts:11:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the new method in interfaces. 9 │ // Works for generic type. 10 │ interface G { > 11 │ new (): G; │ ^^^^^^^^^^^^^ 12 │ } 13 │ i new in an interface suggests it's instantiable, which is incorrect. The returned type should different from the constructor's type. ``` ``` invalid.ts:15:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the constructor method in type aliases. 14 │ type T = { > 15 │ constructor(): void; │ ^^^^^^^^^^^^^^^^^^^^ 16 │ }; 17 │ i Type aliases simply rename types. They don't execute code, so a constructoris misleading. ``` ``` invalid.ts:19:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the new method in classes. 18 │ class C { > 19 │ new(): C; │ ^^^^^^^^^ 20 │ } 21 │ i new is typically used to instantiate objects. In classes, its usage can be misleading. ``` ``` invalid.ts:23:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the new method in classes. 22 │ class C { > 23 │ new(): this; │ ^^^^^^^^^^^^ 24 │ } 25 │ i new is typically used to instantiate objects. In classes, its usage can be misleading. ``` ``` invalid.ts:27:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the new method in classes. 26 │ declare abstract class C { > 27 │ new(): C; │ ^^^^^^^^^ 28 │ } 29 │ i new is typically used to instantiate objects. In classes, its usage can be misleading. ``` ``` invalid.ts:27:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the new method in classes. 26 │ declare abstract class C { > 27 │ new(): C; │ ^^^^^^^^^ 28 │ } 29 │ i new is typically used to instantiate objects. In classes, its usage can be misleading. ``` ``` invalid.ts:31:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the constructor method in interfaces. 30 │ interface I { > 31 │ constructor(): ''; │ ^^^^^^^^^^^^^^^^^^ 32 │ } 33 │ i Interfaces define a contract, not an implementation. Thus, including a constructoris not appropriate. ``` ``` invalid.ts:35:3 lint/suspicious/noMisleadingInstantiator ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ! Don't use the new method in interfaces. 34 │ interface I { > 35 │ new(): this; │ ^^^^^^^^^^^^ 36 │ } 37 │ i new in an interface suggests it's instantiable, which is incorrect. The returned type should different from the constructor's type. ```