A type referenced in a decorated signature must be imported with 'import type...
Production Risk
Build will fail; resolve before shipping.
A syntax error (TS1272): A type referenced in a decorated signature must be imported with 'import type' or a namespace import when 'isolatedModules' and 'emitDecoratorMetadata' are enabled.. This diagnostic is emitted by the TypeScript compiler when a type referenced in a decorated signature must be imported with 'import type' or a namespace import when 'isolatedModules' and 'emitDecoratorMetadata' are enabled..
- 1A decorator is applied incorrectly or to an unsupported target
- 2The 'experimentalDecorators' flag may need to be enabled
TypeScript compiler reports TS1272 during type checking.
// Triggers TS1272 // A type referenced in a decorated signature must be imported with 'import type' or a namespace import when 'isolatedModules' and 'emitDecoratorMetadata' are enabled.
expected output
error TS1272: A type referenced in a decorated signature must be imported with 'import type' or a namespace import when 'isolatedModules' and 'emitDecoratorMetadata' are enabled.
Fix
Enable experimentalDecorators
WHEN Using legacy decorator syntax
// tsconfig.json
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}Why this works
Decorators require the 'experimentalDecorators' flag; TypeScript 5.0+ also supports the TC39 Stage 3 decorator proposal without the flag.
TypeScript Compiler Diagnostics
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev