Skip to content

Add anonymous type declarations #17640

@SamPruden

Description

@SamPruden

This issue is branching out of discussion in #17636, and largely intended to support that feature.

In the language as it stands today, this would look something like

type A<T> = ( type <U> = {value: U}; )<T>;

This is really not very useful. However, #17636 proposes type declaration overloading, which would allow type switching and filtering within the type system. Anonymous type declarations would allow for inline type switches, reducing the need for global type declarations, and support a further proposal that would alleviate the need for #6606, see #17641.

With type declaration overloads, these anonymous type declarations may look something like

type Foo<T> = {
    value: (
        type <U extends number> = {aNumber: number};
        type <U> = {aDefault: U};
    )<T>
};

For details of how the overloading works, see #17636.

Anonymous type declarations (ATDs?) should probably be allowed in interfaces too, such that Foo<T> above could be an interface.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions