Skip to content

Template literal autocomplete not working for parameter objects #46605

Closed
@kadiryazici

Description

@kadiryazici

Bug Report

🔎 Search Terms

typescript cannot get parameter object type when using template literal types

🕗 Version & Regression Information

  • This is a bug
  • I saw this bug when trying to create an object using template literal as keys by first parameter which is object.

⏯ Playground Link

Link

💻 Code

const obj = {
    name: 'Kadir',
    age: 20
}

function listen<T extends {[key: string]: any}>(obj: T, events: {
    [Key in `on${string & keyof T}`]?: Key
}) {

}

// Do CTRL + Space inside second parameter object and you will see
// autocompletion
listen(obj, {
    
})

// Do CTRL + Space inside second parameter
// you will not get any auto completion
listen({ age: 20 }, {
    
})

🙁 Actual behavior

If object is created in first parameter it won't give autocompletion but will give type errors.

🙂 Expected behavior

It should give autocompletion in second parameter object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: Completion ListsThe issue relates to showing completion lists in an editorEffort: ModerateRequires experience with the TypeScript codebase, but feasible. Harder than "Effort: Casual".Help WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions