dot-path-value icon indicating copy to clipboard operation
dot-path-value copied to clipboard

Type of property circularly references itself in mapped type

Open Newbie012 opened this issue 2 years ago • 0 comments

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).

See reproduction

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 🙂

Newbie012 avatar Feb 14 '23 17:02 Newbie012