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
    DuplicateAn existing issue was already created
    and removed
    DuplicateAn existing issue was already created
    on Aug 26, 2022
  4. added
    BugA bug in TypeScript
    Fix AvailableA PR has been opened for this issue
    and removed
    Needs InvestigationThis issue needs a team member to investigate its status.
    on Aug 28, 2022
  5. 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