GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Change 'keyof T' to always be string-like by ahejlsberg · Pull Request #12425 · microsoft/TypeScript

Conversation

@ahejlsberg

@ahejlsberg Anders Hejlsberg (ahejlsberg) commented Nov 21, 2016

Copy link
Copy Markdown
Member

This PR revises keyof T to always be a subtype of string vs. a subtype of string | number. This more accurately reflects how properties work in JavaScript and allows us to use keyof T as the inferred type of a for...in variable when the object is of a type parameter type.

This change means that numeric index signatures are ignored by the keyof T operator and that it is never possible to use numbers as values for a keyof T.

Fixes #12314.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

DanielRosenwasser reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Anders Hejlsberg (ahejlsberg) added 7 commits November 21, 2016 11:41
@ahejlsberg
Make keyof T a string-like type
76ceab9
@ahejlsberg
Update Record<K, T> type
854a20f
@ahejlsberg
Update tests
5498a95
@ahejlsberg
Accept new baselines
c555848
@ahejlsberg
Type of for-in variable is keyof T when object type is a type parameter
1710df5
@ahejlsberg
Accept new baselines
dbc661f
@ahejlsberg
Add test case
b662a8b
@msftclas Microsoft Contribution License Agreements (msftclas) added the cla-not-required label Nov 21, 2016
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Nov 21, 2016

Copy link
Copy Markdown
Member Author

Mohamed Hegazy (@mhegazy) Ping!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

mhegazy
Mohamed Hegazy (mhegazy) approved these changes Nov 21, 2016
View reviewed changes
@ahejlsberg
Anders Hejlsberg (ahejlsberg) merged commit 77c0540 into master Nov 21, 2016
@ahejlsberg
Anders Hejlsberg (ahejlsberg) deleted the keyofOnlyStrings branch November 21, 2016 23:51
@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Nov 22, 2016
Merge master into release-2.1 #12440
Merged
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Nov 24, 2016
Static types for dynamically named properties #11929
Merged
Ethan Resnick (ethanresnick) added a commit to ethanresnick/TypeScript that referenced this pull request Nov 27, 2016
@ethanresnick
Object.keys/entries: remove keyof & string intersections
29105a6
Now that keyof T only returns string or string subtypes (microsoft#12425),
there’s no need to do keyof T & string.
@ethanresnick Ethan Resnick (ethanresnick) mentioned this pull request Nov 27, 2016
Object.keys() types refinement, and Object.entries() types bugfix #12253
Closed
Ethan Resnick (ethanresnick) added a commit to ethanresnick/TypeScript that referenced this pull request Nov 28, 2016
@ethanresnick
Update keyof tests to reflect microsoft#12425
8b7252c
Removes number from all the keyof types, and adds a test that numeric
indexes are ignored.
@ethanresnick Ethan Resnick (ethanresnick) mentioned this pull request Nov 28, 2016
Update keyof tests to reflect #12425 #12533
Merged
Mohamed Hegazy (mhegazy) added a commit that referenced this pull request Nov 28, 2016
@mhegazy
Merge pull request #12533 from ethanresnick/keyof-tests
9cac35b
Update keyof tests to reflect #12425
@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request Dec 19, 2016
Index signature parameter type should allow for enums #2491
Closed
@ChiriVulpes Chiri Vulpes (ChiriVulpes) mentioned this pull request Dec 20, 2016
Enums can not be used for index signature types #13042
Closed
@mhegazy Mohamed Hegazy (mhegazy) mentioned this pull request May 5, 2017
number should be subtype of keyof T[] #13715
Closed
@nevir Ian MacLeod (nevir) mentioned this pull request Jun 29, 2017
Unable to use numeric enums as keys of a map #16842
Closed
@yortus Troy Gerwien (yortus) mentioned this pull request Jan 15, 2018
Index which's key's type is number can accept string keys #21179
Closed
@kpdonn Kevin Donnelly (kpdonn) mentioned this pull request Mar 30, 2018
Consider adding symbolof type operator, like keyof but for unique symbol properties #20721
Closed
@microsoft Microsoft (microsoft) locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

1 more reviewer
@mhegazy Mohamed Hegazy (mhegazy) mhegazy approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@ahejlsberg @mhegazy @msftclas
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.