You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
getTypeFromTypeNodeWorker crashes with TypeError: Cannot read properties of undefined (reading 'kind') #50479
"Cannot read properties of undefined", getInferredTypeParameterConstraint, getTypeFromTypeNodeWorker
🕗 Version & Regression Information
This is a crash
This changed between versions 4.7.4 and 4.8.2
⏯ Playground Link
TBD
💻 Code
TBD
This is occurring in a private repo with a lot of code.
I plan to progressively delete code until I can whittle it down to a minimal repro but that may take several days so until then I thought I'd file this in case anyone has tips on where to start looking.
🙁 Actual behavior
❯ yarn build
yarn run v1.22.19
$ tsc
/home/birtles/referee/node_modules/typescript/lib/tsc.js:98394
throw e;
^
TypeError: Cannot read properties of undefined (reading 'kind')
at getTypeFromTypeNodeWorker (/home/birtles/referee/node_modules/typescript/lib/tsc.js:53060:26)
at getTypeFromTypeNode (/home/birtles/referee/node_modules/typescript/lib/tsc.js:53057:49)
at getEffectiveTypeArgumentAtIndex (/home/birtles/referee/node_modules/typescript/lib/tsc.js:68314:24)
at Array.<anonymous> (/home/birtles/referee/node_modules/typescript/lib/tsc.js:50294:52)
at getMappedType (/home/birtles/referee/node_modules/typescript/lib/tsc.js:53203:46)
at instantiateTypeWorker (/home/birtles/referee/node_modules/typescript/lib/tsc.js:53516:24)
at instantiateTypeWithAlias (/home/birtles/referee/node_modules/typescript/lib/tsc.js:53509:26)
at instantiateType (/home/birtles/referee/node_modules/typescript/lib/tsc.js:53495:37)
at _loop_15 (/home/birtles/referee/node_modules/typescript/lib/tsc.js:50296:58)
at getInferredTypeParameterConstraint (/home/birtles/referee/node_modules/typescript/lib/tsc.js:50327:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
🙂 Expected behavior
Build succeeds.
Reacted by Adam Powers, Patrik Fredriksson, Callum, Niki Micallef, Martin Petrov, Torben, Anton S, Sam Chung, Rhys Arkins and Raph Suttiyotin
The good news is that getEffectiveTypeArgumentAtIndex is only called in one place in the compiler. It happens when computing inferred constraints for infer type parameters occurring as type arguments. For example, in Foo<infer T> we want to infer a constraint for T from the constraint of the corresponding type parameter in Foo. From your stack trace it looks like we're accessing an array of type arguments with an out of bounds index for some reason.
Anyway, look for the Foo<infer T> pattern in a conditional type and you'll likely find the offending construct.
typeCell<ValueextendsBaseValue=any,BaseValue=unknown>={id: string}typeItems<TypeextendsCell=Cell>={type: Typename: string}typeInferIOItemToJSType<TextendsItems>=Textends{type: infer U}
? UextendsCell<infer V/**, infer _ or unknown, or any valid type **/>
? V
: never
: never
➜ tsc-issue npx tsc
/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:98394
throw e;
^
TypeError: Cannot read properties of undefined (reading 'kind')
at getTypeFromTypeNodeWorker (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53060:26)
at getTypeFromTypeNode (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53057:49)
at getEffectiveTypeArgumentAtIndex (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:68314:24)
at Array.<anonymous> (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:50294:52)
at getMappedType (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53203:46)
at instantiateTypeWorker (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53516:24)
at instantiateTypeWithAlias (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53509:26)
at instantiateType (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53495:37)
at _loop_15 (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:50296:58)
at getInferredTypeParameterConstraint (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:50327:21)
Node.js v18.8.0
Activity
moltar commentedon Aug 27, 2022
Confirm getting the same on 4.8.2
ahejlsberg commentedon Aug 27, 2022
The good news is that
getEffectiveTypeArgumentAtIndexis only called in one place in the compiler. It happens when computing inferred constraints forinfertype parameters occurring as type arguments. For example, inFoo<infer T>we want to infer a constraint forTfrom the constraint of the corresponding type parameter inFoo. From your stack trace it looks like we're accessing an array of type arguments with an out of bounds index for some reason.Anyway, look for the
Foo<infer T>pattern in a conditional type and you'll likely find the offending construct.himself65 commentedon Aug 30, 2022
same error here
himself65 commentedon Aug 30, 2022
My package throws the same error after upgrading typescript from
4.7.4to4.8.2See commit: https://github.com/TexteaInc/dev-kit/commit/2f058ecdf918d63e3441fc711d7f23d13afdb74b
himself65 commentedon Aug 30, 2022
I change to this, and the compiler works.
himself65 commentedon Aug 30, 2022
minimum reproduct
➜ tsc-issue npx tsc /Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:98394 throw e; ^ TypeError: Cannot read properties of undefined (reading 'kind') at getTypeFromTypeNodeWorker (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53060:26) at getTypeFromTypeNode (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53057:49) at getEffectiveTypeArgumentAtIndex (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:68314:24) at Array.<anonymous> (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:50294:52) at getMappedType (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53203:46) at instantiateTypeWorker (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53516:24) at instantiateTypeWithAlias (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53509:26) at instantiateType (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:53495:37) at _loop_15 (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:50296:58) at getInferredTypeParameterConstraint (/Users/himself65/Code/ts-node/node_modules/typescript/lib/tsc.js:50327:21) Node.js v18.8.0viceice commentedon Aug 31, 2022
same here
viceice commentedon Aug 31, 2022
is there any way to get more info about the failing code?
build broken by microsoft/TypeScript#50479
ahejlsberg commentedon Sep 15, 2022
This issue is caused by a changed made in #49744. The code in that PR has an incorrect bounds check. Pretty easy fix, I will put up a PR shortly.