Skip to content

Cannot be used to index type error for generic conditional type #50465

Closed

Description

Bug Report

🔎 Search Terms

Generic conditional type index

🕗 Version & Regression Information

  • This is a regression
  • This changed between versions 4.7.4 and 4.8.2

⏯ Playground Link

type Column<T = unknown> = (keyof T extends never ? { id?: number | string } : { id: T }) & {
    title?: string;
}

// no error if `key: keyof Column`
function getColumnProperty<T>(column: Column<T>, key: keyof Column<T>) {
    return column[key];
}
Output
"use strict";
// no error if `key: keyof Column`
function getColumnProperty(column, key) {
    return column[key];
}
Compiler Options
{
  "compilerOptions": {
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictPropertyInitialization": true,
    "strictBindCallApply": true,
    "noImplicitThis": true,
    "noImplicitReturns": true,
    "alwaysStrict": true,
    "esModuleInterop": true,
    "declaration": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "target": "ES2017",
    "jsx": "react",
    "module": "ESNext",
    "moduleResolution": "node"
  }
}

Playground Link: Provided

🙁 Actual behavior

Error:" Type '"title" | keyof (keyof T extends never ? { id?: string | number | undefined; } : { id: T; })' cannot be used to index type '({ id?: string | number | undefined; } | { id: T; }) & { title?: string | undefined; }'.

🙂 Expected behavior

No error

Activity

  1. RyanCavanaugh commented on Aug 26, 2022

    @RyanCavanaugh
    Member

    Bisected to #49119

  2. RyanCavanaugh commented on Aug 26, 2022

    @RyanCavanaugh
    Member

    Let's track at the simpler repro at #50462

  3. added
    Duplicate
    and removed
    Duplicate
    on Aug 26, 2022
  4. added
    Needs Investigation
    on Aug 26, 2022
  5. added
    Bug
    Fix Available
    and removed
    Needs Investigation
    on Aug 28, 2022
  6. 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

BugFix Available

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions