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

Node InferType did not pass test 'isEntityName' #509

Open
marcus-sa opened this issue Nov 16, 2023 · 12 comments · May be fixed by #561
Open

Node InferType did not pass test 'isEntityName' #509

marcus-sa opened this issue Nov 16, 2023 · 12 comments · May be fixed by #561

Comments

@marcus-sa
Copy link
Contributor

marcus-sa commented Nov 16, 2023

The original issue was marked as complete even though it wasn't fixed.

Reproduction

function a<T>(t: T): T {
    return b<T>(t);
}

function b<T>(t: T): T {
    return t;
}

a(1);

Workaround

Disable reflection for the specific scope

/** @reflection never */
@marcus-sa
Copy link
Contributor Author

marcus-sa commented Nov 16, 2023

@marcj I assume it's because of a change in TypeScript. I'm using 5.2.2 here.

@marcus-sa
Copy link
Contributor Author

marcus-sa commented Nov 16, 2023

In my PR for adding Nx to the repository, I had also upgraded the TypeScript version to 5.2.2, and the same error occurred.

@marcj
Copy link
Member

marcj commented Nov 16, 2023

I don't know. The old PR and your patch doesn't fix it, it basically disables the whole sextion since found is then always false, iirc. need to look into it closer to figure out a solution

@marcus-sa
Copy link
Contributor Author

@marcj I'm gonna have a look at it

@marcus-sa
Copy link
Contributor Author

@timvandam did you also have this issue with TypeScript 5.2.2 or was it a different version?

@timvandam
Copy link
Contributor

idk I forgot

@marcj
Copy link
Member

marcj commented Nov 21, 2023

FYI TypeScript 4.9.5 works fine with this code

marcj added a commit that referenced this issue Nov 21, 2023
@marcus-sa
Copy link
Contributor Author

marcus-sa commented Nov 21, 2023

@marcj the following patch to TypeScript fixes the issue for me

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
Contributor Author

@moui72
Copy link

moui72 commented Oct 7, 2024

I discovered that this issue only happens for me if NODE_ENV=development

I don't get this error when NODE_ENV=production, NODE_ENV=, or NODE_ENV=potato

core-api:  NX   Running target build for project core-api and 11 tasks it depends on:
core-api: > nx run shared-common:build
core-api: Compiling TypeScript files for project "shared-common"...
core-api: Done compiling TypeScript files for project "shared-common".
core-api: > nx run shared-deepkit:build
core-api: Compiling TypeScript files for project "shared-deepkit"...
core-api: Done compiling TypeScript files for project "shared-deepkit".
core-api: > nx run shared-auth:build
core-api: Compiling TypeScript files for project "shared-auth"...
core-api: Done compiling TypeScript files for project "shared-auth".
core-api: > nx run core-condition-parser:build
core-api: Compiling TypeScript files for project "core-condition-parser"...
core-api: Done compiling TypeScript files for project "core-condition-parser".
core-api: > nx run shared-typeorm:build
core-api: Compiling TypeScript files for project "shared-typeorm"...
core-api: Done compiling TypeScript files for project "shared-typeorm".
core-api: > nx run shared-nestjs:build
core-api: Compiling TypeScript files for project "shared-nestjs"...
core-api: /Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92389
core-api:   Debug.assertNode(visitedNode, test);
core-api:         ^
core-api: Error: Debug Failure. False expression: Unexpected node.
core-api: Verbose Debug Information: Node InferType did not pass test 'isEntityName'.
core-api:     at visitNode (/Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92389:9)
core-api:     at visitEachChildOfTypeReferenceNode (/Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92787:26)
core-api:     at visitEachChild (/Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92628:33)
core-api:     at searchArgument (/Users/tyler.peckenpaugh/pager/titan/node_modules/@deepkit/type-compiler/dist/cjs/src/compiler.js:1967:32)
core-api:     at visitArrayWorker (/Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92442:49)
core-api:     at visitNodes2 (/Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92413:19)
core-api:     at visitEachChildOfTypeReferenceNode (/Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92788:7)
core-api:     at visitEachChild (/Users/tyler.peckenpaugh/pager/titan/node_modules/typescript/lib/typescript.js:92628:33)
core-api:     at ReflectionTransformer.resolveTypeParameter (/Users/tyler.peckenpaugh/pager/titan/node_modules/@deepkit/type-compiler/dist/cjs/src/compiler.js:1976:54)
core-api:     at ReflectionTransformer.extractPackStructOfTypeReference (/Users/tyler.peckenpaugh/pager/titan/node_modules/@deepkit/type-compiler/dist/cjs/src/compiler.js:1851:22)

I think it's because the error is thrown in Debug.assertNode and Debug.* statements are ignored when NODE_ENV is not development?

@marcj
Copy link
Member

marcj commented Oct 7, 2024

that's weird

@moui72
Copy link

moui72 commented Oct 7, 2024

I think it's because the error is thrown in Debug.assertNode and Debug.* is ignored when NODE_ENV is not development?

i edited my previous post so now this one is pointless but i didn't want to delete it because i am scared of deleting things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants