-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Eliminate circular reference error on type T = Record<string, string | T> #46846
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
Comments
Duplicate of #41164. Looks like you forgot to fill out the "search terms" section. This is used to show that you have searched for existing issues before opening a new one and also to allow future potential issue-filers to find your issue before opening theirs. As an aside, I'll have to remember to use "any arguments to the contrary are fundamentally incorrect" from now on, as it evidently renders claims unassailable. |
Workaround: type T = { [key: string]: string | T }; |
@jcalz I say that because I find this issue so annoying that I wish to express utter disrespect for any counterarguments in advance Things like this often tend to get closed as by design, I'm saying I consider the design itself a problem and ask for it to be changed |
Preemptive disrespect is quite an opening move! |
The counterargument is not "by design" but "design limitation". See #41164 (comment). |
@jcalz not supporting natural recursion is also quite a bold design decision 😉 |
@fatcerberus I'm failing to understand what exactly "generic instantiation is deferred" means in the context of this case, or what that specifically means about why supporting For example the following type seems like it would have problems related to generic instantiation, yet it works: type Stuff<T> = {[x: string]: T | Stuff<T>}
const foo: Stuff<number> = {
a: {
b: {d: 2}
}
} Whatever the supposed design limitations are, the observed behavior from a user perspective seems so illogical that I feel extremely skeptical of the reasoning behind the design limitations. It gives me the hunch that a better design is possible that lacks these unexpected errors but doesn't have any other shortcomings that ostensibly justify the design limitations. |
closing as duplicate |
Bug Report
TS should accept
type T = Record<string, string | T>
instead of flagging a circular reference error. This is self-evidently a valid and well-defined type and any arguments to the contrary are fundamentally incorrect.The equivalent type in Flow works exactly as expected: https://flow.org/try/#0C4TwDgpgBAKlC8UDeBtAzsATgSwHYHMBdALigxwKgB9YBfAKHoGMB7XDKAMxZdLkST0oUAIalBw4QCNSAchGyANEMlNxKyVAAmcgMxKNUBsIYNmbDlJGY+CZCrH3NMqPIOa1Tzdr3vvEUgBGZU1jI3ozVnZgKCsAL1sBB3VnOQUQ1RTvHVd9DM0AqBRCfPCTCKA
🔎 Search Terms
🕗 Version & Regression Information
Seems to be any version of TS 4, tested with 4.4.4
⏯ Playground Link
https://www.typescriptlang.org/play?#code/C4TwDgpgBAKlC8UBKEDGB7ATgEwDwGdhMBLAOwHMAaKQkiqAH1gD4AoIA
💻 Code
🙁 Actual behavior
🙂 Expected behavior
No errors
The text was updated successfully, but these errors were encountered: