dot-path-value
dot-path-value copied to clipboard
Type of property circularly references itself in mapped type
The issue
Given the following code:
import { getByPath } from 'dot-path-value';
type Recursive = {
a: string;
r: Recursive;
};
function x(type: Recursive) {
getByPath(type, '');
~~~~~~~~~~~~
}
we get the following error:
Type of property 'r' circularly references itself in mapped type
'{ [K in //keyof Recursive]-?: PathConcat<K & string, Recursive[K]>; }'.(2615)
which makes sense why it would not print until infinity (or at the max TS iterations).
Suggestion
Don't try to infer the fields of the recursive type, or allow inference for only one level deep.
BTW, really cool library, thanks for sharing 🙂