omit-deep-lodash
omit-deep-lodash copied to clipboard
Add precise TypeScript definitions
First of all: Thank you for this library, we are using it in a project of ours and it is working great for us.
Problem Statement
We rely heavily on static analysis through TypeScript. While lodash's omit
is well-typed, omitDeep
currently is not. That causes a loss of type information that makes dealing with the resulting data more difficult and error prone.
Possible Solution
In our project, we use a wrapper around omit-deep-lodash
and provide type information according to https://gist.github.com/ahuggins-nhs/826906a58e4c1e59306bc0792e7826d1
import omitDeepLodash from 'omit-deep-lodash';
export function omitDeep<T, K>(
value: T,
key: K,
): T extends Array<any> ? DeepOmitArray<T, K> : DeepOmit<T, K> {
return omitDeepLodash(value, key);
}
// Paste https://gist.github.com/ahuggins-nhs/826906a58e4c1e59306bc0792e7826d1 below
Next Steps
Are you generally up for providing TypeScript definitions with this library or possible even convert it to TypeScript entirely? I would be willing to provide a PR.
My proposed solution might not cover every edge case, but so far it is working for us and has improved the typing situtation in our project.