Demystifying TypeScript Decorators
summary
Shows how TypeScript 1.5 implements the ES2016 decorator proposal by transpiling decorators to plain ES5/ES6 using Object.defineProperty and Object.getOwnPropertyDescriptor, so browsers need no native support. Builds real decorators—log, perf and memoize—in Visual Studio Code, wraps original methods via descriptor.value, measures a slow call at ~1001ms and a cached second call at ~0ms, and composes class/property/method decorators successfully.
AI-written summary · about
chapters (11)
- 0:00Introduction and welcome
- 0:26What are TypeScript decorators
- 3:16Browser support and transpilation
- 9:17Setting up the demo project
- 12:49Adding logging manually
- 14:38Creating the log decorator
- 23:07Decorators at class and property level
- 24:59Performance measurement decorator
- 26:01Memoization decorator
- 27:26Real-world decorator libraries
- 30:15Caution and future outlook
related talks
48mFalling in love with decorators ES6/TypeScript
17mWrapping it up with Decorators
46mTypeScript Decorators - Higher Order Functions in Disguise
16mDiscover the power of decorators in TypeScript
40mStandardizing JavaScript Decorators in TC39
27mAdvanced TypeScript: elegant solutions to common problems
46mDecorating JavaScript
21mTypescript meta programming from 0 to 100
