Skip to content

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