Skip to content

Checker loses Array subclass types for mixed index and property key unions #3626

Closed

Description

@nickna
class Child extends Array<string> {}
function read(child: Child, key: '0' | 'length') {
    const wrong: boolean = child[key];
}

SharpTS at 72455db66 accepts this with --no-tsconfig --strict --noEmit. TypeScript 6.0.3 reports TS2322 with --ignoreConfig --strict --target ES2022 --noEmit. The canonical key '0' reads a string element and 'length' reads a number, so the combined result should have type string | number.

Found while verifying #3623, which covers unions where every key is a canonical index.

Activity

  1. added a commit that references this issue on Nov 12, 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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions