Skip to content

Refactoring: Extract to interface #31640

Closed
@DanielRosenwasser

Description

@DanielRosenwasser

The "extract to type alias" code fix is great, however, a lot of people (myself included) prefer interfaces for object types rather than type aliases.

Extract to interface should work only on an intersection type with some number of anonymous object types, named object types, and type references.

Examples

// before
let x: { hello: string, world: string };

// after
interface NewType {
    hello: string;
    world: string;
}

let x: NewType;
// before
let x: { hello: string, world: string } & Record<string, string>;

// after
interface NewType extends Record<string, string> {
    hello: string;
    world: string;
}

let x: NewType;

Related issues:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Refactoringse.g. extract to constant or function, rename symbolEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions