Skip to content

Allow interface extends object syntaxΒ #60730

Open
@HansBrende

Description

@HansBrende

πŸ” 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    In DiscussionNot yet reached consensusSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions