-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Structural Comparison of Circular Tuples #37420
Comments
This is probably fixed by #35741. |
@weswigham awesome to hear! One more thing that I'd like to point out about this scenario: const sadCodec: Codec<
Type.List,
Codec<
Type.List,
Codec<Type.Int>
>
> = [Type.List, [Type.List, [Type.Int]]]; The above produces an error:
... even though the |
I want to spin this into a new pair of issues. The problem can be more easily seen as a failure to propagate constraints type Thing<A> = A extends string ? 1 : 2;
function fn1<T extends string>(n: T): Thing<T> {
// Should be OK
return 1;
}
function fn2<T extends string>(n: T): Thing<T & string> {
// Is OK... but this is a no-op? ^^^^^^^^
return 1;
} The example as written... type Codec<
T extends Type,
C extends Codec<Type> | undefined = undefined
> = C extends undefined ? [T] : [T, C]; ... is harder for us to analyze because its correct behavior depends on knowing that anything that could legally extend I had a local branch to copy the constraint to the restrictive instantiation but it caused new type constraint circularity errors in projects that were too complex to analyze in a reasonable amount of time. |
TypeScript Version: 3.8.2
Search Terms: structure, resolve, compare, equality, type, mismatch, circular, tuple, cycle, recursive
Code
I'm trying to represent some type information for runtime use. I define the following enum:
And I define a
Codec
type: a tuple, within which the first element is the givenType
enum value, and the second element––which is optional––is anotherCodec
:I'm able to assign
Codec
s as expected:And I'm able to create helpers for the
Type.Int
Codec
:However, I'm unable to create helpers for
Codec
s which nest otherCodec
s:This results in an error:
Type '[Type.List, C]' is not assignable to type 'Codec<Type.List, C>'. ts(2322)
.Playground Link
Any thoughts would be greatly appreciated! Thank you!
The text was updated successfully, but these errors were encountered: