Circular reference error when defining Record type
See original GitHub issueTypeScript Version: 4.0.2 (and 4.1.0-dev.20201015)
Search Terms: circularly, Record
Code
type T1 = { [key: string]: T1 }
type T2 = Record<string, T2>
Expected behavior: No compilation errors
Actual behavior:
While type T1 compiles properly, type T2 reports Type alias 'T2' circularly references itself.
even though they are inherently the same type. This was actually found by autofixing a new @typescript-eslint rule consistent-indexed-object-style
Playground Link: https://www.typescriptlang.org/play?ts=4.0.2#code/C4TwDgpgBAKgjFAvFA3lA2gawiAXFAZ2ACcBLAOwHMBdfeKAXwFgAoUSWAJiSgCUIAxgHtiAEwA8RMlQA0XAHxA
Related Issues: None found
Issue Analytics
- State:
- Created 3 years ago
- Reactions:14
- Comments:15 (2 by maintainers)
Top Results From Across the Web
How to create a circularly referenced type in TypeScript?
The creator of TypeScript explains how to create recursive types here. The workaround for the circular reference is to use extends Array ....
Read more >Remove or allow a circular reference - Microsoft Support
If you can't find the error, click the Formulas tab, click the arrow next to Error Checking, point to Circular References, and then...
Read more >PLS-00304 Circular reference - Oracle Communities
thanks for helping me in resolving the follwoing error. USER234@dev>Create or replace package a2 2 is 3 4 TYPE a2_rectype is RECORD
Read more >Jan's Working with Databases: Glossary - JegsWorks
Circular reference : Using a control's name in an expression that defines values for the same ... So you can only edit records...
Read more >The 10 Most Common JavaScript Issues Developers Face
That's why JavaScript issues, and finding the mistakes that cause them, ... By also assigning onClick to element.click , the circular reference is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@RyanCavanaugh not sure what’s under the hood of
Record
, but it does feel a bit inconsistent that some generics seem to work fine with recursions while others don’t:Certain circularities are allowed (e.g. T1) but other circularities aren’t, e.g.
Generic instantiation is deferred, so at the point TS analyzes
T2
’s declaration, it can’t tell if it’s in theRecord
case (would be allowed) or theIdentity
case (would not be allowed). It’s only later in the process that we could tell that this is actually OK, but if it wasn’t OK, it’s “too late” to go back and start complaining about it.