Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Keyof function args suggest all keys #36025

Copy link
Copy link
@ar53n

Description

@ar53n
Issue body actions

TypeScript Version: 3.7.2

Search Terms:
keyof interface function arguments args

Code

export interface ISocialButtonTypes {
  vk: {vk: string};
  fb: {fb: string};
  ok: {ok: string};
  twitter: {tw: string};
};

export type createSocialItem = <T extends keyof ISocialButtonTypes>(
  socialType: T,
  params: ISocialButtonTypes[T]
) => void;

function createSocialItem<T extends keyof ISocialButtonTypes>(
  socialType: T,
  params?: ISocialButtonTypes[T]
): ISocialButtonTypes[T] {
  return params
}
// the compiler show error, but suggest all keys
createSocialItem('vk', { ok: 'dwdw' })
                        ~~~~~~~~~~~~~

Expected behavior:
The second param should suggest only vk key.

Actual behavior:
The params field suggests all keys, but the compiler show error on the incorrect key. The function return works correctly

Playground Link:
https://cutt.ly/cruK8eX

Related Issues:

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already createdAn existing issue was already created

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.