Skip to content

Avoid pulling on setter type when only getter type is needed to break circularity #47818

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

Merged
merged 1 commit into from
Feb 9, 2022

Conversation

andrewbranch
Copy link
Member

Fixes #44906

interface User {
  firstName: string,
  level: number,
  get bestFriend(): User
  set bestFriend(user: SerializablePartial<User>)
}

type FilteredKeys<T> = { [K in keyof T]: T[K] extends number ? K : T[K] extends string ? K : T[K] extends boolean ? K : never }[keyof T];

type SerializablePartial<T> = {
  [K in FilteredKeys<T>]: T[K]
};

In the process of instantiating SerializablePartial<User> on the setter type, we need to pull the reading type for User["bestFriend"]. However, the function that gets the read type for a get accessor prematurely resolved the type of the set accessor, which created a circularity. That circularity is easily broken in this case, since we were only interested in the getter type.

@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Feb 9, 2022
@andrewbranch andrewbranch merged commit 2cf5afd into microsoft:main Feb 9, 2022
@andrewbranch andrewbranch deleted the bug/44906 branch February 9, 2022 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot define getter and setter, getting an error: "circularly references itself in mapped type"
4 participants