microsoft / microsoft/TypeScript

Allow `interface extends object` syntax

Open
#60,730 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

In Discussion Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

🔍 Search Terms

interface extends object

✅ Viability Checklist
⭐ Suggestion

I propose to allow the following syntax:

interface MyInterface extends object {}

This would have identical semantics to the following (currently legal) syntax:

type _object = object
interface MyInterface extends _object {}

Details:

  1. No primitive may be assigned to such an interface or an intersection containing such an interface
  2. This requirement is inherited by any extending interfaces

I'm requesting this feature mainly because it was the only pain-point mentioned in this related issue. To quote:

No one is going to turn on this behavior if it means every time they write

interface Person {
  name: string
}

they actually need to write

interface _PersonFields {
  name: string;
}
type Person = object & _PersonFields;

Regardless of the outcome of that other issue however, it would be nice to be able to extends object without going through that kind of hassle.

📃 Motivating Example

A small usability improvement to allow interfaces to more easily declare that primitives cannot be assigned to them.

💻 Use Cases
  1. What do you want to use this for? To avoid non-idiomatic verbosity
  2. What shortcomings exist with current approaches? Non-idiomatic verbosity
  3. What workarounds are you using in the meantime? Non-idiomatic verbosity

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 reviewing the proposed interface extends object syntax and the linked related issue #60582. No implementation files or tests are named, so trace the relevant interface heritage and assignability handling before defining tests for the stated primitive-assignment semantics.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.