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