I think the following example says it all.
/**
* @param {ReturnType<typeof n2>} a
* @param {string} b
*/
function n1(a, b) { // Error: 'a' is referenced directly or indirectly in its own type annotation.
return [a, b]
}
function n2() {
/** @typedef {Parameters<typeof n1>[1]} T */ // type T = any -- Error: Type alias 'T' circularly references itself.
return /** @param {T} ol */ (ol) => n1
}
The second parameter at index 1 is string, so I would like T to be of type string
instead (which is the case if I don’t bind it as the parameter type of ol
.
I guess the issue lies in how TS resolves type aliases. I think it just takes the definition of the alias, inserts it wherever it is used, and then resolves it, which is fine. But, for my use case, I need that type to be resolved outside the context of the return value of n2
. This is a minimal reproduction of the issue. I know it probably would just do to define the type of ol
as string
directly. However, I have a more complex use case.