Closed shlyk closed 5 hours ago
(Note: I'm not a TS team member, feel free to ignore me if you want to wait for official word)
You checked this:
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
but it's clearly a runtime feature (non-ECMAscript syntax with JavaScript output). If you want this feature it needs to be a JS feature first (that is, it should look like your proposal but without the type annotations, such as extension Array { first() { const [first] = this; return first; } isEmpty() { return this.length === 0; } }
) and then TS will support it. Stuff like this needs to go through the TC39 process and isn't in scope for TypeScript until it reaches Stage 3 of that process.
Nothing substantial has changed from https://github.com/microsoft/TypeScript/issues/9#issuecomment-174407229.
This proposal will be declined. You might want to save the TS team the trouble of doing so by closing this yourself.
🔍 Search Terms
TypeScript Extensions Declaration merging
✅ Viability Checklist
⭐ Suggestion
A proposal to add first-class extensions to TypeScript, enabling developers to extend existing classes in a type-safe and modular way.
Well, right now you could:
TypeScript extensions would elegantly bridge the gap between JavaScript's prototype-based inheritance and TypeScript's type system by providing a safe, controlled way to extend objects that aligns with both languages' core principles:
1. Alignment with JavaScript's Prototype Nature
2. Type-Safe Prototype Enhancement Instead of unsafe and discouraging modifications like:
We get something clean and simple like this:
3. Zero Runtime Overhead
The original request was made in 2014, but with TypeScript's current maturity and the proven success of extensions in other languages, it might be time to revisit this feature. The modern TypeScript team might have a different perspective now, especially given:
📃 Motivating Example
Swift, Kotlin, and C# — these languages have proven that extensions aren’t just a nice-to-have feature — they’re a game-changer for code organization and maintainability. What’s exciting is that we can learn from all of these implementations, taking the best parts of each while adapting them to TypeScript’s unique characteristics and use cases:
Swift Extensions Kotlin Extensions C# Extension Methods
💻 Use Cases