Skip to content

tsc crashes resolving a type of computed property in destructiring assignment #26321

Closed

Description

TypeScript Version: 3.1.0-dev.20180809, 3.0.1

Search Terms:
Cannot read property 'charCodeAt' of undefined

Code

interface Limit1 {
    propName: { min: number; max: number };
}
interface Limit2 {
    propName: { min: number; max: number };
}

type Limit = Limit1 | Limit2; // should be Union type

export interface Meta {
    propName: "propName";
}

function foo (meta: Meta, limits: Limit): void {
    const {
        [`propName`]: { min: minBonus, max: maxBonus }, // should be computed
    } = limits;
}

Expected behavior:
No crash, code compiled

Actual behavior:

Cannot read property 'charCodeAt' of undefined
.../node_modules/typescript/lib/tsc.js:68035
                throw e;
                ^

TypeError: Cannot read property 'charCodeAt' of undefined
at isLateBoundName (.../node_modules/typescript/lib/tsc.js:28756:25)
at createUnionOrIntersectionProperty (.../node_modules/typescript/lib/tsc.js:29638:38)
at getUnionOrIntersectionProperty (.../node_modules/typescript/lib/tsc.js:29699:28)
at getPropertyOfUnionOrIntersectionType (.../node_modules/typescript/lib/tsc.js:29707:28)
at getPropertyOfType (.../node_modules/typescript/lib/tsc.js:29727:24)
at checkVariableLikeDeclaration (.../node_modules/typescript/lib/tsc.js:43025:36)
at checkBindingElement (.../node_modules/typescript/lib/tsc.js:43123:20)
at checkSourceElement (.../node_modules/typescript/lib/tsc.js:44827:28)
at Object.forEach (.../node_modules/typescript/lib/tsc.js:168:30)
at checkVariableLikeDeclaration (.../node_modules/typescript/lib/tsc.js:43036:20)

Playground Link:

Note, that the code is not compiled

Activity

  1. ghost added
    BugA bug in TypeScript
    on Aug 9, 2018
  2. ghost added
    FixedA PR has been merged for this issue
    on Aug 9, 2018
  3. ghost closed this as completedin #26334on Aug 9, 2018
  4. martpie commented on Aug 27, 2018

    @martpie

    Andy (Andrewkraft) (@Andy-MS) Has it been released yet? I am facing this issue too.

    Or can you recommend a way to mitigate it in the meantime?

  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
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 TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions