TypeScript 5.0: Decorators Standard and const Type Params
Use the new decorators proposal and const generic parameters.
TypeScript 5.0: Decorators Standard and const Type Params is a free TypeScript Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the TypeScript Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
TypeScript 5.0 Overview
TypeScript 5.0 brought the standardized TC39 decorators proposal (Stage 3), const type parameters, new verbatim module syntax, and significant performance improvements.
// TS 5.0 release: March 2023
// npm install typescript@5Stage 3 Decorators
TS 5.0 implements the official TC39 Stage 3 decorators proposal — different from the legacy experimental decorators. No more experimentalDecorators: true needed.
// New standard decorator — no experimentalDecorators flag needed
function logged(target: Function, ctx: ClassDecoratorContext) {
return class extends (target as any) {
constructor(...args: any[]) {
console.log("Creating", target.name);
super(...args);
}
};
}
@logged
class User { constructor(public name: string) {} }Decorator Context Object
New decorators receive a typed ClassDecoratorContext or MethodDecoratorContext object with metadata about the decorated element.
function sealed(_: Function, ctx: ClassDecoratorContext) {
ctx.addInitializer(function(this: any) {
Object.seal(this);
});
}Method Decorators in TS 5.0
Method decorators receive the method and a ClassMethodDecoratorContext, replacing the old (target, key, descriptor) signature.
function measure(_: Function, ctx: ClassMethodDecoratorContext) {
return function(this: any, ...args: any[]) {
const start = performance.now();
const result = (_.apply as any)(this, args);
console.log(ctx.name, performance.now() - start, "ms");
return result;
};
}const Type Parameters
const on a type parameter makes TypeScript infer literal types for arguments instead of widening to the base type.
function identity<const T>(val: T): T { return val; }
const a = identity("hello"); // type: "hello" (not string)
const b = identity([1, 2, 3]); // type: readonly [1, 2, 3]const Generics vs as const
const type parameters apply the narrowing effect automatically — callers don't need to add as const at each call site.
// Without const param: callers need as const
function makeRoute<T extends string>(path: T) { return path; }
const r1 = makeRoute("/home" as const); // "/home"
// With const param: automatic
function makeRoute2<const T extends string>(path: T) { return path; }
const r2 = makeRoute2("/home"); // "/home" — no as const neededBundler Module Resolution
TS 5.0 added moduleResolution: "bundler" for projects using Vite, esbuild, or similar bundlers that handle module resolution themselves.
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler"
}
}verbatimModuleSyntax
verbatimModuleSyntax: true enforces that type-only imports use import type, preventing runtime import leakage.
// tsconfig.json
{ "compilerOptions": { "verbatimModuleSyntax": true } }
// Now this errors: must be import type
import { User } from "./types"; // Error if User is only a type
import type { User } from "./types"; // OKPerformance Improvements
TS 5.0 improved type instantiation caching and narrowing performance, making large projects faster without code changes.
# TS 5.0 compile benchmarks: ~10-15% faster on large projectsMigration from Legacy Decorators
Legacy experimentalDecorators still work but will eventually be deprecated. Migrate to TC39 decorators for future compatibility.
// Legacy: requires experimentalDecorators: true
@Component({ selector: "app-root" })
class AppComponent {}
// New TC39 decorator: no flag needed (but Angular/NestJS need updates)Recap: TypeScript 5.0
TypeScript 5.0 delivered TC39 standard decorators, const type parameters for automatic literal inference, moduleResolution: "bundler", verbatimModuleSyntax, and significant performance gains.
Quick Check
What does const on a type parameter do?
What You Learned
TypeScript 5.0: standard TC39 decorators replace experimental ones, const type parameters auto-narrow arguments to literal types, moduleResolution: "bundler" supports modern build tools, and verbatimModuleSyntax enforces import type.
Frequently asked questions
Is the “TypeScript 5.0: Decorators Standard and const Type Params” lesson free?
Yes — the full text of “TypeScript 5.0: Decorators Standard and const Type Params” is free to read here on the web, and the TypeScript Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the TypeScript Academy course, upgrade to CoddyKit PRO.
What will I learn in “TypeScript 5.0: Decorators Standard and const Type Params”?
Use the new decorators proposal and const generic parameters. You practise TypeScript Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start TypeScript Academy?
No prior experience is required. TypeScript Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “TypeScript 5.0: Decorators Standard and const Type Params” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this TypeScript Academy lesson?
Yes. Every TypeScript Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- TypeScript 5.0: Decorators Standard and const Type Params
- TypeScript 5.1-5.2: Improved Inference
- TypeScript 5.3-5.4: New Narrowing and NoInfer
- TypeScript 5.5+: Isolated Declarations and Beyond