- Error
- Reported by the type checker
TS7009
'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.
`new` is used on a value that has no construct signature, so the result would be `any`. Call a class, or type the value as a constructor.
What it means
Under noImplicitAny, calling new on something whose type has no construct signature (for example a plain function type) produces an implicit any. In TypeScript files only classes and values typed with new (...) => T can be constructed.
Example
declare const makeUser: (name: string) => { name: string };
export const u = new makeUser("ada");
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,18): error TS7009: 'new' expression, whose target lacks a construct signature, implicitly has an 'any' type.
Recorded by node scripts/verify-examples.mjs with ts-r built from commit 6deaf01. The example uses the default tsconfig: strict, target: es2022, module: esnext, moduleResolution: bundler.
How to fix
- Call it without
newif it's a plain function:makeUser("ada"). - Turn it into a class, or give it a construct signature in its type:
declare const User: new (name: string) => { name: string }.