Swifter
Swifter11mo ago

circular type reference nonsense

2 Replies
Swifter
Swifter11mo ago
to be more clear about the type definition I'm looking for here, it should accept: - [1, [1, 'test']] - [[1, [1, 'test']], [1, 'test']] - [[1, [1, 'test']], [[[1, [1, 'test']], [1, 'test']], 'test']] - [1, [[1, [[[1, [1, 'test']], [[1, [1, 'test']], 'test']], 'test']], 'test']] and so on basically it starts off with a base [...number[], [...number[], string]] but any of the ...number[]s can be replaced with the entire expression recursively
Deno AI Helper
Deno AI Helper11mo ago
The error you're seeing is not related to circular dependencies, but rather to TypeScript's structural type system. In TypeScript, two types are considered identical if their structures (i.e., their properties and methods) are identical. In your code, you have an interface Foo that has a property bar of type Bar[]. Bar is an interface that has a property foo of type Foo. This creates a circular reference between Foo and Bar, because Foo refers to Bar and Bar refers back to Foo. When you remove the array from the bar property in Foo, TypeScript sees Foo and Bar as identical, because their structures are now the same: they both have a single property of the same type. This is why you're getting the error "Type alias 'Foo' circularly references itself." To fix this, you could make Foo and Bar distinct in some way. For example, you could add another property to one of them. This would make their structures different, and TypeScript would no longer consider them to be the same type. Please note that this explanation is based on the general principles of TypeScript's type system and not on the specific documentation provided.