microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.4k stars 12.41k forks source link

`abstract class` should be usable in expressions #59031

Open stwlam opened 3 months ago

stwlam commented 3 months ago

🔍 Search Terms

abstract, class, expression

✅ Viability Checklist

⭐ Suggestion

function myMixin(Base: typeof Object) {
  return abstract class Mixed extends Base {};
}

📃 Motivating Example

Preferable to:

function myMixin(Base: typeof Object) {
  abstract class Mixed extends Base {}
  return Mixed;
}

💻 Use Cases

  1. What do you want to use this for? Same uses as without
  2. What shortcomings exist with current approaches? Slight additional verbosity
  3. What workarounds are you using in the meantime? Slight additional verbosity
whzx5byb commented 3 months ago

https://github.com/microsoft/TypeScript/issues/4578 was declined, but since it's 9 years, maybe it's time to revisit it.

stwlam commented 3 months ago

4578 was declined, but since it's 9 years, maybe it's time to revisit it.

Interesting! image

stwlam commented 3 months ago

Some additional issue corralling: it looks like the reporter of #32122 was basically running into the same problem, though the errors they pasted aren't the same.