Enabling experimentalDecorators in tsconfig.json
You'll learn how to configure TypeScript to support the older decorator syntax using the experimentalDecorators compiler option.
What This Configuration Does
TypeScript has supported decorators for years through an experimental implementation based on an earlier proposal. This older syntax differs from the Stage 3 decorators you've been learning about. To use this legacy decorator format (which many existing libraries still rely on), you must explicitly enable it in your TypeScript configuration file.
Think of it like choosing between two different plug standards — the experimental decorators are the older format that many tools were built around, while Stage 3 decorators are the modern, standardized approach.
The Configuration Setting
In your tsconfig.json file, you add this compiler option:
{
"compilerOptions": {
"experimentalDecorators": true
}
}
This tells TypeScript's compiler to accept and process decorators using the older experimental syntax rules. Without this flag, TypeScript will either reject decorators entirely or expect Stage 3 decorator syntax (depending on your TypeScript version).
Why This Matters
Many popular frameworks and libraries (like Angular, TypeORM, and NestJS) were built using experimental decorators before Stage 3 decorators were standardized. If you're working with these tools, you'll need this setting enabled. However, be aware that experimental decorators work differently under the hood — they have different signatures, different context objects, and different capabilities.
Key Takeaway: Set "experimentalDecorators": true in tsconfig.json to use the older decorator syntax that many existing TypeScript libraries depend on, but remember this is separate from the modern Stage 3 decorator standard.