GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Allow template string index signatures · Issue #43136 · microsoft/TypeScript Closed DescriptionSuggestion🔍 Search Termstemplate string index signature number bigint ✅ Viability ChecklistMy suggestion meets these guidelines:
⭐ SuggestionCurrently, only strings or numbers can be used as index signatures. Until template strings were added, mapped types could work around this: // this won't work: // type Foo = {[x: 'foo' | 'bar']: number} // this does: type Foo = {[K in 'foo' | 'bar']: number} // or alternatively Record<'foo' | 'bar', number> However, when attempting to use mapped types for template string types, the type becomes type TemplateString = `${number}: ${string}` // DoesntWork is {} type DoesntWork = Record<TemplateString, number> 📃 Motivating ExampleSay you had a UUID type: type UUID = `${string}-${string}-${string}-${string}-${string}` This feature would allow more type-safe index signatures (instead of simply interface User { username: string // ... } const users: Record<UUID, User> users['01234567-89ab-cdef-0123-456789abcdef'] = {username: 'Alice'} // Compile error users['invalid'] = {username: 'Bob'} // Compile error const someUser = users['invalid'] I'll change this example if I or anyone else comes up with a better one. 💻 Use CasesDiscord uses snowflakes, which are 64-bit integers, for IDs. The package discord-api-types exports this: export type Snowflake = `${bigint}` My use case is that I want to have a An alternative that would fix my specific use case would be to allow Activity
MetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| 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. |