Skip to content

Imperative type definition #62145

@finom

Description

@finom

🔍 Search Terms

imperative typescript interface

✅ Viability Checklist

⭐ Suggestion

I work on a library that requires to use lots of 3rd party generic types, multiple mappings and more or less complex typing, and I've got to repeat one complex type multiple times or create another generic that is going to contain a lot of parameters and will complicate the code that's already complicated.

(these types have bugs, they just an illustration)
Image

📃 Motivating Example

I imagine it as an "type function" that has function body that returns any valid type.

imperative type Foo<T> {
  type X = Bar<T>;
  type Y = Baz<T>;

  return { x: X, y: Y };
}

type Quix = Foo<string>;
// Quix { x: Bar<string>, y: Baz<string> }

// ... vs
interface Foo<T> {
  x: Bar<T>;
  y: Baz<T>;
}

💻 Use Cases

  • Imperative style
  • Shorter syntax for complex types

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions