Skip to content

Fix recursive types in @typedef #40861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 2, 2020
Merged

Conversation

sandersn
Copy link
Member

@sandersn sandersn commented Sep 30, 2020

Previously this code path was broken and untested. Fortunately the fix is simple -- the code that looks for the alias' host needs to skip the JSDoc type expression node as it walks up the tree.

Fixes #39372
Fixes #40234

Previously this code path was broken and untested. Fortunately the fix
is simple.
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Sep 30, 2020
@sandersn sandersn changed the title Fix reference types in @typedef Fix recursive types in @typedef Sep 30, 2020
@sandersn
Copy link
Member Author

sandersn commented Oct 2, 2020

Oops, forgot to update baselines now that type aliases created by typedefs are properly deferred. I'll do that.

@sandersn sandersn merged commit b8ebad4 into master Oct 2, 2020
@sandersn sandersn deleted the fix-recursive-typedef-references branch October 2, 2020 15:46
@kungfooman
Copy link

Why does this work for:

/** @typedef {Json[]} JsonArray */
/** @typedef {{ readonly [key: string]: Json }} JsonRecord */
/** @typedef {boolean | number | string | null | JsonRecord | JsonArray | readonly []} Json */

But not if JsonRecord is defined like this:

/** @typedef {Object<string, Json>} JsonRecord */

Then it errors with: Type alias 'JsonRecord' circularly references itself.

(thank you a lot for this PR, it is already tremendously useful)

@sandersn
Copy link
Member Author

@kungfooman can you open a fresh bug for that?

@kungfooman
Copy link

@kungfooman can you open a fresh bug for that?

@sandersn There is this one already, I think it's the same issue: #46369

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

JSDocs @typedef parsing runs into infinite loop Jsdoc Type alias circularly references itself
4 participants