Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zmzlois opened this issue Dec 27, 2022 · 1 comment
Open

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

zmzlois opened this issue Dec 27, 2022 · 1 comment

Comments

@zmzlois
Copy link

zmzlois commented Dec 27, 2022

.....

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

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

interface Comment {
  id: User["id"];
  comment: string;
}
@Korazza
Copy link

Korazza commented Mar 29, 2023

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants