Skip to content

Keyof function args suggest all keys #36025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ar53n opened this issue Jan 6, 2020 · 2 comments
Closed

Keyof function args suggest all keys #36025

ar53n opened this issue Jan 6, 2020 · 2 comments
Labels
Duplicate An existing issue was already created

Comments

@ar53n
Copy link

ar53n commented Jan 6, 2020

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:

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Jan 6, 2020
@RyanCavanaugh
Copy link
Member

Going to track this general class of behavior at #35702

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants