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 — Allow any key type as an index signature parameter type by weswigham · Pull Request #26797 · microsoft/TypeScript

Conversation

@weswigham

@weswigham Wesley Wigham (weswigham) commented Aug 30, 2018 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This allows, eg, symbol:

interface SymbolMap {
  [x: symbol]: string;
}

interface PropertyMap {
  [x: string | number | symbol]: string;
}

// same as
interface PropertyMap {
  [x: PropertyKey]: string;
}

enums:

enum Cardinal {
  North = "n",
  South = "s",
  West = "w",
  East = "e"
}
interface CardinalDataMap {
  [dir: Cardinal]: number;
}

enum Places {
  None,
  First,
  Second,
  Third
}
interface PlaceMap {
  [dir: Places]: number;
}

literal unions:

interface AdjacencyMap {
  [side: "top" | "bottom" | "left" | "right"]: number;
}

and generics:

interface PartialElementMap<TElements extends keyof HTMLElementTagNameMap> {
  [elem: TElements]: HTMLElement;
}

interface SpyProxy<T> {
  [field: keyof T]: Function;
}

as index signature parameter types.
Much of this functionality also exists in mapped types, except they had trouble shuffling around symbol information since there was no kind of index signature a symbol could map to. Unlike mapped types, however, since these are just index signatures, they can be added into any object type and in multiples.

Fixes #26470
Fixes #1863 (caveat: well-known symbols are not currently checked as part of a symbol index signature! Such checking should fall out from removing the concept of well-known symbols and using unique symbols instead)
Fixes #2491 in the original sense (rather than with mapped types).

Related: #28315

Sorry, something went wrong.

Uh oh!

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

9034725985, styfle, nikcorg, yortus, attente, DLehenbauer, levenleven, Tiberriver256, sanex3339, HerringtonDarkholme, and 399 more reacted with thumbs up emoji Val0429, mtpultz, LM-G, crushjz, brianle1301, ZhuoYitao, wrsx, Azarlak, ftzi, trevorhreed, and 60 more reacted with hooray emoji dfreeman, yortus, aleclarson, sanex3339, ahtcx, oyvindberg, mbkv, j-oliveras, dfoverdx, ferdaber, and 101 more reacted with heart emoji amitbeck, jorroll, mtpultz, niieani, brianle1301, Azarlak, trevorhreed, wsmd, matthewmueller, charlesferreira, and 39 more reacted with rocket emoji trevorhreed, wsmd, matthewmueller, charlesferreira, davidcallanan, NN---, ryotah, danieldelcore, ujinho, whaqzhzd, and 12 more reacted with eyes emoji
All reactions
  • 👍 409 reactions
  • 🎉 70 reactions
  • ❤️ 111 reactions
  • 🚀 49 reactions
  • 👀 22 reactions
Wesley Wigham (weswigham) added 7 commits August 24, 2018 17:14
@weswigham
Heavy WIP
cb1e630
@weswigham
Merge branch 'master' into mappedtype-inference-seperate-symbols
b21c2ab
@weswigham
Adjustments, fixes, and edits, oh my
8a6154a
@weswigham
Accept most baselines
8bdcc78
@weswigham
A whole new paradigm of index signature relating strategies
0183d39
@weswigham
Merge branch 'master' into mappedtype-inference-seperate-symbols
4174ab9
@weswigham
Remove grammar restriction and add tests
2c47d31
@weswigham

Wesley Wigham (weswigham) commented Aug 30, 2018

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) test this

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Aug 30, 2018 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Wesley Wigham (@weswigham), I've started to run the extended test suite on this PR at 2c47d31. You can monitor the build here. It should now contribute to this PR's status checks.

All reactions

Sorry, something went wrong.

Uh oh!

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

@weswigham
Wesley Wigham (weswigham) requested review from Daniel Rosenwasser (DanielRosenwasser), Ryan Cavanaugh (RyanCavanaugh), Anders Hejlsberg (ahejlsberg) and Nathan Shively-Sanders (sandersn) August 30, 2018 22:41
@weswigham Wesley Wigham (weswigham) mentioned this pull request Aug 31, 2018
Computed property union lifting #21070
Closed
@dfreeman Dan Freeman (dfreeman) mentioned this pull request Sep 5, 2018
Support symbols or strings as milestone keys salsify/milestones#12
Merged
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Sep 7, 2018
Design Meeting Notes, 8/31/2018 #26954
Closed
@weswigham
Merge branch 'master' into mappedtype-inference-seperate-symbols
fcb90ea
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) added this to the TypeScript 3.2 milestone Sep 17, 2018
@jack-williams Jack Williams (jack-williams) mentioned this pull request Sep 19, 2018
Cannot use valid union type as a map's key #27219
Closed
@weswigham Wesley Wigham (weswigham) mentioned this pull request Sep 20, 2018
Regression with >= v3 and React, generics, defaultProps #26395
Closed
@weswigham
Merge branch 'master' into mappedtype-inference-seperate-symbols
2435298
@weswigham Wesley Wigham (weswigham) mentioned this pull request Sep 26, 2018
Regex Validated String Types #21044
Closed
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) mentioned this pull request Oct 1, 2018
Design Meeting Notes, 9/28/2018 #27486
Closed
Tommy Ru (tommy20061222) pushed a commit to tommy20061222/safe-mock that referenced this pull request Oct 28, 2018
tru
(1) upgrade typescript to 3.1.3
7f06b35
(2) typescript 2.9 not allow symbol to be used as index. microsoft/TypeScript#1863. Current there is a PR open to address this issue microsoft/TypeScript#26797
@weswigham
Merge branch 'master' into mappedtype-inference-seperate-symbols
c88702b
@weswigham Wesley Wigham (weswigham) mentioned this pull request Nov 14, 2018
An index signature parameter type with types extends string or number. #28519
Open
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Nov 16, 2018
Design Meeting Notes, 11/16/2018 #28581
Closed
@yortus Troy Gerwien (yortus) mentioned this pull request Nov 21, 2018
Allow indexing with symbols #1863
Closed
@jhpratt

Jacob Pratt (jhpratt) commented Nov 22, 2018

Copy link
Copy Markdown

Ryan Cavanaugh (@RyanCavanaugh) I see you marked this for TS 3.2. Is that still the plan?

All reactions

Sorry, something went wrong.

Uh oh!

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

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) removed this from the TypeScript 3.2 milestone Nov 29, 2018
@MartinJohns Martin Johns (MartinJohns) mentioned this pull request Mar 8, 2021
Allow template string index signatures #43136
Closed
5 tasks done
@orta

Orta Therox (orta) commented Mar 18, 2021

Copy link
Copy Markdown
Contributor

TypeScript Bot (@typescript-bot) pack this

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 18, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Heya Orta Therox (@orta), I've started to run the tarball bundle task on this PR at 05f63f6. You can monitor the build here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@typescript-bot

TypeScript Bot (typescript-bot) commented Mar 18, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Hey Orta Therox (@orta), I've packed this into an installable tgz. You can install it for testing by referencing it in your package.json like so:

{
    "devDependencies": {
        "typescript": "https://typescript.visualstudio.com/cf7ac146-d525-443c-b23c-0d58337efebc/_apis/build/builds/98697/artifacts?artifactName=tgz&fileId=FCFFE06ACEDE5A9CF492C0B487ADB414731BE223F7CF66D693D5A513375E6B9102&fileName=/typescript-4.3.0-insiders.20210318.tgz"
    }
}

and then running npm install.


There is also a playground for this build and an npm module you can use via "typescript": "npm:@typescript-deploys/[email protected]".;

All reactions

Sorry, something went wrong.

Uh oh!

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

@benmccann Ben McCann (benmccann) mentioned this pull request Mar 18, 2021
typecheck in CI sveltejs/kit#445
Merged
This was referenced Mar 25, 2021
Support symbols as Record keys runtypes/runtypes#199
Closed
How to represent rest properties in Object runtypes/runtypes#201
Open
@nana4gonta

nana4gonta (nana4gonta) commented Mar 30, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Hello, I found this PR and I am looking forward to its release.

A question about this PR.
I want to define an object type that can only accept a numeric string as a key.
In the following code, why does an error occur for the key "100"?

type NumStr = `${number}`
type Obj = { [key: `${NumStr}`]: string }
const obj: Obj = { 
    "0xff": "", // OK
    "100e10": "", // OK
    "100": "", // NG, but why?
}
// Type '{ "0xff": string; "100e10": string; "100": string; }' is not assignable to type 'Obj'.
// Object literal may only specify known properties, and '"100"' does not exist in type 'Obj'.

Playground Link

Shinigami92, disjukr, tjjfvi, ShanTulshi, alvis, listiani13, zone117x, josh-hemphill, ExE-Boss, dioxmio, and 2 more reacted with eyes emoji
All reactions
  • 👀 12 reactions

Sorry, something went wrong.

Uh oh!

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

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Apr 20, 2021
Design Meeting Notes, 4/9/2021 #43742
Closed
@yuhr Sʜɪᴍᴜʀᴀ Yū (yuhr) mentioned this pull request Apr 29, 2021
Number-like key check in Dictionary is incorrect runtypes/runtypes#244
Closed
@microsoft Microsoft (microsoft) deleted a comment from tuanggolt (tuanggolt) Apr 29, 2021
@weswigham
Merge branch 'master' into mappedtype-inference-seperate-symbols
d14bd57
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request May 24, 2021
TypeScript 4.4 Iteration Plan #44237
Closed
@RyanCavanaugh

Ryan Cavanaugh (RyanCavanaugh) commented May 24, 2021

Copy link
Copy Markdown
Member

#41821

All reactions

Sorry, something went wrong.

Uh oh!

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

@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) mentioned this pull request Jun 2, 2021
Design Meeting Notes, 6/2/2021 #44400
Closed
@jcalz Joe Calzaretta (jcalz) mentioned this pull request Jun 3, 2021
Object.fromEntries: return type does not account for symbols #44405
Closed
@mykohsu

mykohsu commented Jun 4, 2021 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Could this support optional indexers? This seems to work with the in operator but not the : operator.

type OptionalKeyedType = {
  [k in typeof ENUM[keyof typeof ENUM]]?: unknown;
};

interface DirectOptionalKeyed {
  [k: typeof ENUM[keyof typeof ENUM]]?: unknown; // ';' expected.(1005)
}

Playground link

All reactions

Sorry, something went wrong.

Uh oh!

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

@MartinJohns Martin Johns (MartinJohns) mentioned this pull request Jun 6, 2021
Multiple index signatures allowing different index types #44468
Closed
5 tasks done
@ghost ghost mentioned this pull request Jun 6, 2021
Extended theme customisation syntax microsoft/vscode#122969
Merged
@dgreif Dusty Greif (dgreif) mentioned this pull request Jun 8, 2021
data-test-id can be used with OverlayProps primer/react#1275
Merged
@ahejlsberg Anders Hejlsberg (ahejlsberg) mentioned this pull request Jun 8, 2021
Index signatures for symbols and template literal strings #44512
Merged
@runspired Chris Thoburn (runspired) mentioned this pull request Jun 17, 2021
Conditionals checks of the key used with Mapped Types don't work as expected #44625
Closed
@MartinJohns Martin Johns (MartinJohns) mentioned this pull request Jun 20, 2021
Object Indexing with a Template String #44675
Closed
@MartinJohns

Martin Johns (MartinJohns) commented Jul 12, 2021

Copy link
Copy Markdown
Contributor

Wesley Wigham (@weswigham) What's the status of this? The PR is still open and has the "Backlog" milestone, yet on the roadmap it's marked as done and already part of typescript@next.

All reactions

Sorry, something went wrong.

Uh oh!

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

@MartinJohns Martin Johns (MartinJohns) mentioned this pull request Jul 12, 2021
keyof ignores constraint #44985
Closed
@ahejlsberg

Anders Hejlsberg (ahejlsberg) commented Jul 12, 2021

Copy link
Copy Markdown
Member

What's the status of this?

It's been superseded by #44512.

Idonoghue and chbdetta reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) closed this Jul 12, 2021
@andrewbranch Andrew Branch (andrewbranch) mentioned this pull request Jul 21, 2021
Improve parser error on mapped type with additional property declarations #45089
Closed
5 tasks done
@0-CAT Zero Cat (0-CAT) mentioned this pull request Jun 1, 2023
Add XMP raw string type to ExpandedTags["xmp"] type mattiasw/ExifReader#197
Merged
@microsoft Microsoft (microsoft) locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@ahejlsberg Anders Hejlsberg (ahejlsberg) Awaiting requested review from ahejlsberg
@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) Awaiting requested review from RyanCavanaugh
@sandersn Nathan Shively-Sanders (sandersn) Awaiting requested review from sandersn
@DanielRosenwasser Daniel Rosenwasser (DanielRosenwasser) Awaiting requested review from DanielRosenwasser
1 more reviewer
@MananTheMoon Manan Thakkar (MananTheMoon) MananTheMoon approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

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

Assignees

@weswigham Wesley Wigham (weswigham)

Labels

Author: Team Experiment A fork with an experimental idea which might not make it into master For Backlog Bug PRs that fix a backlog bug For Milestone Bug PRs that fix a bug with a specific milestone

Projects

None yet

Milestone

Backlog

Development

Successfully merging this pull request may close these issues.

Intuitive != expected != actual behaviour when combining string and symbol keys Index signature parameter type should allow for enums Allow indexing with symbols

Uh oh!

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

20 participants

@weswigham @typescript-bot @jhpratt @chriskrycho @Jessidhia @groege @Misaka-0x447f @Telokis @tombuckley91 @jpike88 @benwiley4000 @motechFR @spaceemotion @ProdigySim @dead-claudia @leidegre @mutech @ChromeQ @DanielRosenwasser @tjjfvi
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.