Cannot define getter and setter, getting an error: "circularly references itself in mapped type" #44906
Labels
Bug
A bug in TypeScript
Fix Available
A PR has been opened for this issue
Rescheduled
This issue was previously scheduled to an earlier milestone
Milestone
Cannot define getter and setter, getting an error: "Type of property '..' circularly references itself in mapped type ..."
Error:
Type of property 'bestFriend' circularly references itself in mapped type '{ [K in keyof User]: User[K] extends number ? K : User[K] extends string ? K : User[K] extends boolean ? K : never; }'.(2615)
, Link to playgroundAnd here is almost the same valid example without error where I only changed getter
get bestFriend(): User
to methodgetBestFriend(): User
and setterset bestFriend(user: SerializablePartial<User>)
to methodsetBestFriend(user: SerializablePartial<User>): void
. Link to playgroundSo semantically it's all the same, the difference is only in syntactic sugar - using getter and setter instead of "getX" and "setX" methods and seems like it should have the same type checking path
🔎 Search Terms
circularly references itself in mapped type
🕗 Version & Regression Information
v4.3.5
⏯ Playground Link
Playground link with bug
Playground link with working get-set-methods version
🙁 Actual behavior
getting an error
🙂 Expected behavior
no error
Relevant issue
There already was some issue with "circularly references itself in mapped type" in #38279 and it was fixed in #38653 but seems like it was the fix only for methods not for getter/setters
The text was updated successfully, but these errors were encountered: