Skip to content

ts2536 thrown when use key remapping to filter out some keys #45212

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
gulewei opened this issue Jul 28, 2021 · 1 comment Β· Fixed by #45700
Closed

ts2536 thrown when use key remapping to filter out some keys #45212

gulewei opened this issue Jul 28, 2021 · 1 comment Β· Fixed by #45700
Assignees
Labels
Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript

Comments

@gulewei
Copy link
Contributor

gulewei commented Jul 28, 2021

Bug Report

πŸ”Ž Search Terms

key remapping
ts2536

πŸ•— Version & Regression Information

  • This is a crash
  • v4.3.5

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

type Methods<T> = { [P in keyof T as T[P] extends Function ? P : never]: T[P] };
type H<T> = T[keyof Methods<T>]; // here it throws

πŸ™ Actual behavior

Type keyof Methods<T> cannot be used to index type T. (2536)

πŸ™‚ Expected behavior

key remapping in type Methods<T> dose not make new keys, only filter out some of it. I think it could be used to type T in this case.

@andrewbranch
Copy link
Member

I agree, though type H<T> = Methods<T>[keyof Methods<T>] is a pretty straightforward workaround.

@andrewbranch andrewbranch added Experience Enhancement Noncontroversial enhancements Suggestion An idea for TypeScript labels Aug 5, 2021
@andrewbranch andrewbranch added this to the TypeScript 4.5.0 milestone Aug 5, 2021
@typescript-bot typescript-bot added the Fix Available A PR has been opened for this issue label Sep 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Experience Enhancement Noncontroversial enhancements Fix Available A PR has been opened for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants