microsoft / microsoft/TypeScript

Allow `abstract` modifier on construct signature in object type literal

Open
#57,171 3 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.4k
Avg merge
1d 19h
Merged PRs (30d)
117

Description

🔍 Search Terms

'abstract' modifier cannot appear on a type member

✅ Viability Checklist
⭐ Suggestion

Allow using abstract new … constructor definition keywords in an interface, i.e. in an object form (i.e., within curly braces).

📃 Motivating Example

Consider possible definitions of:

  • a function (a callable object),
  • a non-abstract constructor,
  • an abstract constructor.

All of those definitions can be created through type aliasing:

type Callable = () => void // ✅
type Constructor = new () => void // ✅
type ConstructorAbstract = abstract new () => void // ✅

But only the first two definitions can be created using an object form:

type Callable = { (): void } // ✅
type Constructor = { new (): void } // ✅
type ConstructorAbstract = { abstract new (): void } // ❌
//                           ^^^^^^^^
// Error: 'abstract' modifier cannot appear on a type member

Try it.

Apparently, in this form the token new is considered a method name, rather than a keyword.

I suggest making the last one a valid expression by parsing new as a keyword.

💻 Use Cases

This suggestion is mainly for visual consistency, there is no functional change sought to be. To the folks who prefer using interfaces whenever possible (like me), the requirement of using type here is somewhat unreasonable, although it doesn't pose any significant problems.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the accepted type-alias forms and the rejected abstract new object form in the linked TypeScript Playground. Read the motivating examples and determine how the object form should parse and type-check while preserving the existing behavior of callable and non-abstract constructor members. Done means the object-form declaration is accepted and behaves consistently with the equivalent abstract new type alias.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.