Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pkudryashov opened this issue Aug 26, 2022 · 2 comments Β· Fixed by #50497
Closed

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

pkudryashov opened this issue Aug 26, 2022 · 2 comments Β· Fixed by #50497
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@pkudryashov
Copy link

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

@RyanCavanaugh
Copy link
Member

Bisected to #49119

@RyanCavanaugh
Copy link
Member

Let's track at the simpler repro at #50462

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Aug 26, 2022
@RyanCavanaugh RyanCavanaugh removed the Duplicate An existing issue was already created label Aug 26, 2022
@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Aug 26, 2022
@ahejlsberg ahejlsberg added Bug A bug in TypeScript Fix Available A PR has been opened for this issue and removed Needs Investigation This issue needs a team member to investigate its status. labels Aug 28, 2022
@ahejlsberg ahejlsberg added this to the TypeScript 4.9.0 milestone Aug 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants