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
Array.protoype.from is malformed without a mapping predicate function. Granted, the predicate should be used instead of a map, but it gave very unusual results:
If the mapFn is nil and the arrayLike is just an object with a length property set, like {length=16}, the whole thing just doesn't do anything because of how Lua tables handle nil assignments.
Lua doesn't offer an elegant solution to this problem. We'd either have to pack the table with zeros in this case, or perhaps throw an exception or warning. I'm not sure if interface declaration merging can at least warn users to make them aware of this issue in the TypeScript environment like by adding a deprecation warning or something. I tried to create an 'exact' type in TypeScript to handle the scenario where the passed object only has a 'length', but it seems that the built-in typescript definition clauses for 'from' still override this custom instruction. Due to declaration merging rather than replacing, the only thing I was able to leak through was the deprecation warning:
typeHasOnlyLengthProp<T>=T&{[KinkeyofTasExclude<K,'length'>]: never;};interfaceArrayConstructor{/** * @deprecated Do not use this process due to broken interaction within Lua. */from<T>(arrayLike: HasOnlyLengthProp<T>,mapFn: never): [];}
The text was updated successfully, but these errors were encountered:
Hi,
Array.protoype.from is malformed without a mapping predicate function. Granted, the predicate should be used instead of a map, but it gave very unusual results:
If the mapFn is nil and the arrayLike is just an object with a length property set, like {length=16}, the whole thing just doesn't do anything because of how Lua tables handle nil assignments.
Lua doesn't offer an elegant solution to this problem. We'd either have to pack the table with zeros in this case, or perhaps throw an exception or warning. I'm not sure if interface declaration merging can at least warn users to make them aware of this issue in the TypeScript environment like by adding a deprecation warning or something. I tried to create an 'exact' type in TypeScript to handle the scenario where the passed object only has a 'length', but it seems that the built-in typescript definition clauses for 'from' still override this custom instruction. Due to declaration merging rather than replacing, the only thing I was able to leak through was the deprecation warning:
The text was updated successfully, but these errors were encountered: