Skip to content

Another solution for Q14: declare precise value in interface #72

Open
@zmzlois

Description

@zmzlois

.....

interface User {
  id: string;
  firstName: string;
  lastName: string;
}

interface Post {
  id: User["id"];
  title: string;
  body: string;
}

interface Comment {
  id: User["id"];
  comment: string;
}

Activity

Korazza

Korazza commented on Mar 29, 2023

@Korazza

If there were a thousand interfaces with the id field, and one day you wanted to change only the id type of User to number, you would then have to change id: User["id"] in each interface. So compared to the given solution, the code would be less maintainable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Korazza@zmzlois

        Issue actions

          Another solution for Q14: declare precise value in interface · Issue #72 · total-typescript/beginners-typescript-tutorial