You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to represent some type information for runtime use. I define the following enum:
enumType{Int="Int",List="List",}
And I define a Codec type: a tuple, within which the first element is the given Type enum value, and the second element––which is optional––is another Codec:
Type '[Type.List, [Type.Int]]' does not satisfy the constraint '[Type]'.
Types of property 'length' are incompatible.
Type '2' is not assignable to type '1'.
... even though the Codec type has an arity of 1 or 2. Hoping this helps with the solution. & thank you for adding to the 4.0 milestone!
I want to spin this into a new pair of issues. The problem can be more easily seen as a failure to propagate constraints
typeThing<A>=Aextendsstring ? 1 : 2;functionfn1<Textendsstring>(n: T): Thing<T>{// Should be OKreturn1;}functionfn2<Textendsstring>(n: T): Thing<T&string>{// Is OK... but this is a no-op? ^^^^^^^^return1;}
... is harder for us to analyze because its correct behavior depends on knowing that anything that could legally extend Codec<Type> could not possibly extend undefined, but that sort of counterfactual analysis is difficult to get right 100% of the time apart from these sorts of edge cases that can be easily rewritten anyway.
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.
Activity
weswigham commentedon Mar 16, 2020
This is probably fixed by #35741.
harrysolovay commentedon Mar 17, 2020
Wesley Wigham (@weswigham) awesome to hear! One more thing that I'd like to point out about this scenario:
The above produces an error:
... even though the
Codectype has an arity of 1 or 2. Hoping this helps with the solution. & thank you for adding to the 4.0 milestone!6 remaining items
RyanCavanaugh commentedon Feb 15, 2023
I want to spin this into a new pair of issues. The problem can be more easily seen as a failure to propagate constraints
The example as written...
... is harder for us to analyze because its correct behavior depends on knowing that anything that could legally extend
Codec<Type>could not possibly extendundefined, but that sort of counterfactual analysis is difficult to get right 100% of the time apart from these sorts of edge cases that can be easily rewritten anyway.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.