You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My use case is that I want to have a Record<Snowflake, SomeType>, but I was a little surprised and disappointed when that turned out to be {}.
An alternative that would fix my specific use case would be to allow bigints in index signatures, but in my opinion that would be confusing as property keys are converted to strings anyway. I believe allowing template strings in index signatures is a more general solution that could be helpful in many use cases.
The text was updated successfully, but these errors were encountered:
Suggestion
π Search Terms
template string index signature number bigint
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
Currently, only strings or numbers can be used as index signatures. Until template strings were added, mapped types could work around this:
However, when attempting to use mapped types for template string types, the type becomes
{}
:π Motivating Example
Say you had a UUID type:
This feature would allow more type-safe index signatures (instead of simply
Record<UUID, User>
, for example):I'll change this example if I or anyone else comes up with a better one.
π» Use Cases
Discord uses snowflakes, which are 64-bit integers, for IDs. The package discord-api-types exports this:
My use case is that I want to have a
Record<Snowflake, SomeType>
, but I was a little surprised and disappointed when that turned out to be{}
.An alternative that would fix my specific use case would be to allow
bigint
s in index signatures, but in my opinion that would be confusing as property keys are converted to strings anyway. I believe allowing template strings in index signatures is a more general solution that could be helpful in many use cases.The text was updated successfully, but these errors were encountered: