Skip to content

TS 5.8 TypeError: Cannot read properties of undefined (reading 'kind')Β #61351

Closed

Description

@zxbodya

πŸ”Ž Search Terms

TypeError: Cannot read properties of undefined (reading 'kind')

πŸ•— Version & Regression Information

⏯ Playground Link

https://www.typescriptlang.org/dev/bug-workbench/?ts=5.8.2#code/KYDwDg9gTgLgBDAnmYcDKMCGNUF44DeAsAFBxyYBccAdgK4C2ARsFANynlPUDOMUASxoBzDiQC+Y0qEiw4AYwA2mHjzgAVYH2Jk4PYDAzZgACj7HqRnAEoC4zgi3x8J4NUw1E1uLgB8hB3IAM2g4E3kIGj44AG0Aa2BEABo4ADdMRTpgAF04CCC4AHkmACtgeRgAOmAafgEtV2tvHXJWhAALAR5K-UMsHBMWttb4xOzqdMzgJMDW8WsxNvtdSVJl0iA

πŸ’» Code

export type State = {
  a: number;
  b: string;
};

export class Test{
  setState(state: State){}
  test = (e: any) => {
    for (const [key, value] of Object.entries(e)) {
      this.setState({
        [key]: value,
      });
    }
  };
}

πŸ™ Actual behavior

running tsc results in a crash:

TypeError: Cannot read properties of undefined (reading 'kind')

πŸ™‚ Expected behavior

No crash is expected, some type errors should be found instead.

Additional information about the issue

No response

Activity

  1. lnunno commented on May 28, 2025

    @lnunno

    Wondering what the status of this one is and if the linked PR can be reviewed / merged?

  2. RudiVuuren commented on Jun 4, 2025

    @RudiVuuren

    It seems the compiler fails to use variables declared by a tuple as index keys. For those of you looking for a workaround in the meantime: redefine your tuples to rather be normal variables (using Object.keys and Object.values for above example) instead.

    Workaround

    Before

    for (const [key, value] of Object.entries(data)) {
        data = { [key]: value };
    }

    After

    for (const key in data) {
        data = { [key]: data[key] };
    }
  3. martinslota commented on Jun 17, 2025

    @martinslota

    An alternative, potentially a bit more type-friendly workaround (e.g. when using noUncheckedIndexedAccess ) is to keep using Object.entries() but destructure the entries in a separate statement.

    Before

    for (const [key, value] of Object.entries(data)) {
        console.log(key, value);
    }

    After

    for (const entry of Object.entries(data)) {
        const [key, value] = entry;
        console.log(key, value);
    }
  4. locked as resolved and limited conversation to collaborators on Jan 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions