Skip to content
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

visitor of visitEachChild doesn't support returning InferTypeNode #56480

Closed
marcus-sa opened this issue Nov 21, 2023 · 4 comments
Closed

visitor of visitEachChild doesn't support returning InferTypeNode #56480

marcus-sa opened this issue Nov 21, 2023 · 4 comments
Assignees
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@marcus-sa
Copy link

marcus-sa commented Nov 21, 2023

πŸ”Ž Search Terms

False expression: Unexpected node
Node InferType did not pass test 'isEntityName'.

πŸ•— Version & Regression Information

⏯ Playground Link

No response

πŸ’» Code

https://github.com/marcus-sa/deepkit-framework/blob/9c9eb001459a4e1046aea94cb531ba5d8ca3b1c9/packages/type-compiler/src/compiler.ts#L2353-L2370

πŸ™ Actual behavior

Visitor callback of visitEachChild doesn't support returning InferTypeNode when the node is a TypeReferenceNode

Verbose Debug Information: Node InferType did not pass test 'isEntityName'.
           at visitNode (/Users/marcus-sa/Git/deepkit/deepkit-framework/node_modules/typescript/lib/typescript.js:87180:11)
           at visitEachChildOfTypeReferenceNode (/Users/marcus-sa/Git/deepkit/deepkit-framework/node_modules/typescript/lib/typescript.js:87589:32)
           at visitEachChild (/Users/marcus-sa/Git/deepkit/deepkit-framework/node_modules/typescript/lib/typescript.js:87421:35)
           at ReflectionTransformer.resolveTypeParameter (file:///Users/marcus-sa/Git/deepkit/deepkit-framework/packages/type-compiler/dist/esm/src/compiler.js:1910:54)

πŸ™‚ Expected behavior

For it to work

@marcus-sa marcus-sa changed the title visitEachChild doesn't support InferTypeNode vistor of visitEachChild doesn't support returning InferTypeNode Nov 21, 2023
@marcus-sa marcus-sa changed the title vistor of visitEachChild doesn't support returning InferTypeNode visitor of visitEachChild doesn't support returning InferTypeNode Nov 21, 2023
@marcus-sa
Copy link
Author

marcus-sa commented Nov 21, 2023

The following patch fixes it (or at least works around it):

diff --git a/node_modules/typescript/lib/typescript.js b/node_modules/typescript/lib/typescript.js
index 86ab90b..dc72ecb 100644
--- a/node_modules/typescript/lib/typescript.js
+++ b/node_modules/typescript/lib/typescript.js
@@ -87586,7 +87586,7 @@ ${lanes.join("\n")}
         [183 /* TypeReference */]: function visitEachChildOfTypeReferenceNode(node, visitor, context, nodesVisitor, nodeVisitor, _tokenVisitor) {
           return context.factory.updateTypeReferenceNode(
             node,
-            Debug.checkDefined(nodeVisitor(node.typeName, visitor, isEntityName)),
+            Debug.checkDefined(nodeVisitor(node.typeName, visitor, node => isTypeNode(node) || isEntityName(node))),
             nodesVisitor(node.typeArguments, visitor, isTypeNode)
           );
         },

@marcus-sa
Copy link
Author

marcus-sa commented Mar 17, 2024

@andrewbranch where are we with this? I would gladly make a PR.

@rbuckton rbuckton added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Needs Investigation This issue needs a team member to investigate its status. labels Mar 18, 2024
@rbuckton
Copy link
Member

A TypeReferenceNode shouldn't have an InferTypeNode in its typeName property, so the error you see is correct and indicates a problem in your code. Looking at the code you linked to, I believe you are incorrectly updating the tree with a node in an invalid position. You shouldn't be replacing an Identifier with an InferTypeNode, you should be looking for the TypeReferenceNode containing that identifier and replace it instead.

const searchArgument = (node: Node): Node => {
    node = visitEachChild(node, searchArgument, this.context);

    if (isTypeReferenceNode(node) && isIdentifier(node.typeName) && node.typeName.escapedText === argumentName) {
        //transform to infer T
        found = true;
        node = this.f.createInferTypeNode(declaration);
    }

    return node;
};

@rbuckton rbuckton closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
@marcus-sa
Copy link
Author

@rbuckton thanks a lot!

marcus-sa added a commit to marcus-sa/deepkit-framework that referenced this issue Mar 19, 2024
microsoft/TypeScript#56480 (comment)

Signed-off-by: Marcus S. Abildskov <8391194+marcus-sa@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants