`& DepSafe` API inconvenience due to tsc weakness
TypeScript is not able to understand that T & DepSafe is an "object type", and so using an element of an array obtained from Values.toArray in contexts such as a spread expression are disallowed. E.g. {...(vals.toArray()[0], k: v} is a type error and needs a cast. Is there anything to do to help tsc?
That type does include non-object inhabitants in general: null, number, boolean, etc.
Does the case you have in mind have some other constraint that T is an object type? If not, I'm not sure there's anything we can do.
Oh, yes, sorry, I indeed meant in cases where T is an object type already.
It is annoying since, while typescript is not documented, the handbook does not give any indication that & makes sense for anything other than object types.
Looking again here, I believe the error is not because T & DepSafe isn't understood as an object type but actually because Typescript doesn't know that vals.toArray() is non-empty, so vals.toArray()[0] is understood as (T & DepSafe) | undefined. Does it work if you do vals.toArray()[0]! instead? (or just vals.getUnique() if there is only the one unique element)
Sorry, I failed to do a good job of simplifying without adding new issues. Where I ran into this was with code performing a for loop like for (const v of values.toArray()), so I think that the undefined shouldn't matter there. I have also seen such casts needed when trying to spread the result of getUnique.