Skip to content

getTypeFromTypeNodeWorker crashes with TypeError: Cannot read properties of undefined (reading 'kind') #50479

Closed

Description

Bug Report

🔎 Search Terms

"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.

Activity

  1. moltar commented on Aug 27, 2022

    @moltar

    Confirm getting the same on 4.8.2

  2. ahejlsberg commented on Aug 27, 2022

    @ahejlsberg
    Member

    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.

  3. himself65 commented on Aug 30, 2022

    @himself65

    same error here

  4. himself65 commented on Aug 30, 2022

    @himself65

    My package throws the same error after upgrading typescript from 4.7.4 to 4.8.2

    See commit: https://github.com/TexteaInc/dev-kit/commit/2f058ecdf918d63e3441fc711d7f23d13afdb74b

  5. himself65 commented on Aug 30, 2022

    @himself65

    My package throws the same error after upgrading typescript from 4.7.4 to 4.8.2

    See commit: TexteaInc/dev-kit@2f058ec

    I change to this, and the compiler works.

    Index: src/sheet/index.mts
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/src/sheet/index.mts b/src/sheet/index.mts
    --- a/src/sheet/index.mts	(revision 27521b1858b6e1485de0a15de8b220bdcd00e9c4)
    +++ b/src/sheet/index.mts	(date 1661828501343)
    @@ -134,7 +134,7 @@
     
     export type InferIOItemToJSType<T extends IOItem> =
       T extends { type: infer U }
    -    ? U extends AbstractCellType<infer V>
    +    ? U extends AbstractCellType<infer V, unknown>
           ? V
           : never
         : never
    
  6. himself65 commented on Aug 30, 2022

    @himself65

    minimum reproduct

    type Cell<Value extends BaseValue = any, BaseValue = unknown> = {
      id: string
    }
    
    type Items<Type extends Cell = Cell> = {
      type: Type
      name: string
    }
    
    type InferIOItemToJSType<T extends Items> =
      T extends { type: infer U }
        ? U extends Cell<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
  7. viceice commented on Aug 31, 2022

    @viceice

    is there any way to get more info about the failing code?

  8. ahejlsberg commented on Sep 15, 2022

    @ahejlsberg
    Member

    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.

  9. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFix AvailableA PR has been opened for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions