I have been using your improved types for a better part of this last year, and I came into an example of a type that breaks the interface, and I honestly have no idea why. (Also doesn't work with original type)
The issue is that in the Subpath type we exclude all of the properties of an array, which includes the length property, this results in foo.length being excluded even though in this case length is a property on an object. One way to fix this is to change the exclusion to only apply if the type is an array:
Thanks for the great article.
I was messing around with the string dot Path type, I think it can be made a little simpler by splitting it into two types
Subpath gets the paths for properties of T, and Path stitches them all together into a single type.
PathType can also be made a lot more concise by using type intersection on Key and Rest
I'm not sure if this is easier to understand than the original though.
Here's the result.
This is great stuff!
I have been using your improved types for a better part of this last year, and I came into an example of a type that breaks the interface, and I honestly have no idea why. (Also doesn't work with original type)
Counter example of the interface not correctly idenying
foo.test
@nroboto do you know what's going on here? Am i missing something?
The issue is that in the
Subpath
type we exclude all of the properties of an array, which includes thelength
property, this results infoo.length
being excluded even though in this caselength
is a property on an object. One way to fix this is to change the exclusion to only apply if the type is an array:Here's the TS playground.