-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
Bug Report
π Search Terms
generics object keys, autocomplete
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ
β― Playground Link
Playground link with relevant code
π» Code
const select_fn = <T, K extends keyof T>(dataKey: K) => { };
const select_fn_with_data = <T, K extends keyof T>(data: T, dataKey: K) => { };
type CommonObj = {
elements: string[],
id: number;
name: string;
}
const cObj: CommonObj = {
elements: [],
id: 1,
name: ''
}
select_fn<CommonObj, 'elements'>('elements') // works ts check of types
select_fn<CommonObj, ''>('') // no autocomplete, but shows error - Type '""' does not satisfy the constraint 'keyof CommonObj'
select_fn_with_data(cObj, 'elements') // works fine
π Actual behavior
no keys in autocomplete
π Expected behavior
when I provide an object type to the first generic param, I expect that autocomplete works and shows keys in the second generic param.
djolejov
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created