Closed pixelzoom closed 2 years ago
The current implementations of DerivedProperty and Multilink are limited to 15 dependencies. In the above example, I could certainly have more than 15 atoms.
For 2 real-world examples of this problem, see equality-explorer EquationNode.ts, and the multiple // @ts-ignore
comments related to relationalOperatorMultilink
and termsMultilink
.
This kind of problem is best solved with multilinkAny
which returns type UnknownMultilink
. Here is a working patch which demonstrates its use in EquationNode.ts:
For DerivedProperty, the analog is deriveAny
which returns UnknownDerivedProperty
.
Great thanks. I had no idea that Multilink.multilinkAny or UnknownMultilink existed. The former has no documentation, the latter has inadequate documentation, see https://github.com/phetsims/axon/issues/418.
DerivedProperty and Multilink have a similar problem when their dependencies are computed. For example:
The usage of
dependencies
on the 2nd line results in TS error:I've also tried this, which results in the same error:
DerivedProperty and Multilink have multiple constructors, and the number of values in the first arg (
dependencies
) is used to infer type. Whendependencies
is computed, that hack doesn't work. And I can't explicitly specify the type, because I don't know how many dependencies there will be - in the example above, it varies based on the number of atoms.Thoughts on how to address this? This pattern is used in several places in Equality Explorer, which I'm in the process of converting to TS in https://github.com/phetsims/equality-explorer/issues/186.