Skip to content

IntelliSense/autocomplete doesn't work for object keysΒ #48984

@woophi

Description

@woophi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions