- Error
- Reported by the type checker
TS1206
Decorators are not valid here.
A decorator is placed on something that cannot be decorated, such as a function declaration or a variable statement.
What it means
Decorators apply to classes and class members (and, with experimentalDecorators, parameters of class methods and constructors). On other declarations, such as plain functions, variable statements or constructors, they're reported here.
Example
function log(target: unknown) {}
@log
function run() {}
export {};
ts-r-check -p tsconfig.json --pretty false ts-r outputindex.ts(2,1): error TS1206: Decorators are not valid here.
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 the function yourself instead:
const run = log(function run() {}), or wrap it in a class. - Move the decorator to a class or class member.