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

Cannot read properties of undefined (reading 'length') #51623

Closed
nevedaren opened this issue Nov 22, 2022 · 2 comments Β· Fixed by #51762
Closed

Cannot read properties of undefined (reading 'length') #51623

nevedaren opened this issue Nov 22, 2022 · 2 comments Β· Fixed by #51762
Assignees
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue

Comments

@nevedaren
Copy link

Bug Report

πŸ”Ž Search Terms

Cannot read properties of undefined, tsc crash

πŸ•— Version & Regression Information

First noticed on 5.0.0-dev.20221118 nightly build, persists on 5.0.0-dev.20221122

⏯ Playground Link

https://www.typescriptlang.org/play?module=1&ts=5.0.0-dev.20221122#code/KYDwDg9gTgLgBDAnmYcBiEIB4AqcC8cAzjFAJYB2A5gHwFwDeAvgNwBQbA9J3AAIBmZADbAKAQwC2wAFxxBIgEwA6GEQ5kJkWIwwQmcqBAlwA5Es6UwAVxgn2bflYoBjGGQgU4AIzFRcNAApgESkKGFldAEpGNjg4KGAYKyhPAEZ2Jg4fKADUuDEidEwsCisJL2AoGkiWIA

πŸ’» Code

// main.ts
import {Foo} from './x';

function bar<T>(element: Foo) {
  return 1;
}

bar(1 as Foo<number>);
// x.ts
export type Foo<T = string> = {};

πŸ™ Actual behavior

A crash:

/usr/local/lib/node_modules/typescript/lib/tsc.js:98593
      throw e;
      ^

TypeError: Cannot read properties of undefined (reading 'length')
    at inferFromTypeArguments (/usr/local/lib/node_modules/typescript/lib/tsc.js:55506:54)
    at inferFromTypes (/usr/local/lib/node_modules/typescript/lib/tsc.js:55314:11)
    at inferTypes (/usr/local/lib/node_modules/typescript/lib/tsc.js:55300:5)
    at inferTypeArguments (/usr/local/lib/node_modules/typescript/lib/tsc.js:61051:11)
    at chooseOverload (/usr/local/lib/node_modules/typescript/lib/tsc.js:61672:33)
    at resolveCall (/usr/local/lib/node_modules/typescript/lib/tsc.js:61539:16)
    at resolveCallExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:61870:12)
    at resolveSignature (/usr/local/lib/node_modules/typescript/lib/tsc.js:62215:16)
    at getResolvedSignature (/usr/local/lib/node_modules/typescript/lib/tsc.js:62235:20)
    at checkCallExpression (/usr/local/lib/node_modules/typescript/lib/tsc.js:62340:23)

πŸ™‚ Expected behavior

Success or compilation errors.

@nicolas377
Copy link
Contributor

Running git bisect with this repro shows the error popped up at a3092c7 (#51152).

@ahejlsberg ahejlsberg added Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output labels Nov 23, 2022
@ahejlsberg ahejlsberg added this to the TypeScript 5.0.0 milestone Nov 23, 2022
@Andarist
Copy link
Contributor

Andarist commented Nov 23, 2022

This particular error goes away with this patch (unfortunately, it breaks other things though):

diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts
index 92a989a2bc..394fa24674 100644
--- a/src/compiler/checker.ts
+++ b/src/compiler/checker.ts
@@ -14901,7 +14901,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
                     const resolved = resolveAlias(aliasSymbol);
                     if (resolved && resolved.flags & SymbolFlags.TypeAlias) {
                         newAliasSymbol = resolved;
-                        aliasTypeArguments = typeArgumentsFromTypeReferenceNode(node);
+                        aliasTypeArguments = getTypeArgumentsForAliasSymbol(newAliasSymbol);
                     }
                 }
             }

I'm not entirely sure if this patch produces a correct result for this test case as I'm not entirely sure what to expect out of the .types and .symbols snapshots here. It compiles and doesn't produce any errors though.

weswigham added a commit to weswigham/TypeScript that referenced this issue Dec 5, 2022
@weswigham weswigham mentioned this issue Dec 5, 2022
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Dec 5, 2022
weswigham added a commit that referenced this issue Dec 5, 2022
* Fix #51623

* Revert newline changes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Crash For flagging bugs which are compiler or service crashes or unclean exits, rather than bad output Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants