Hi there, I have a complex question that I would like some help with.
I've created a recursive Omit
type in TypeScript. It takes a type T
and a tuple of strings (referred to as a 'path'), then removes the last item on the path and returns the resulting type.
I've researched similar topics such as Deep Omit With Typescript and Type Safe Omit Function, but they don't quite fit my requirements.
Here is my implementation:
// code snippet goes here
I want to restrict the Path
parameter to be a valid traversal of
T</code, following a specific format.</p>
<p><strong>First Attempt</strong></p>
<p>I tried creating a type called <code>ExistingPathInObject
to check if a given path is valid within an object structure. However, due to circular dependency issues, I couldn't enforce it as part of the signature for DeepOmit
.
Second Attempt
To overcome this, I attempted to generate a union of all possible paths within a type using the Paths
type. This allowed me to verify paths against this union, although the implementation got a bit convoluted.
Now, I'm struggling to rewrite DeepOmit
while incorporating these constraints. Although I managed to make it work with a helper type, the code looks messy and requires additional checks that should ideally be handled by the Paths
type itself.
In summary, I'm looking for a cleaner way to validate paths and potentially support a union of paths for multiple omits. Currently, the output of my function yields a union of individual omit results, which may not be ideal.