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
Current best workaround is to define an overloaded function with [path, value] parameter pairs, but the downside is you can't supply a map or list of tuples (e.g. during class construction etc.).
The text was updated successfully, but these errors were encountered:
Never mind. It just so happens I made a mistake when trying to define multiple template literal index signatures, where both resolved to the same template literal type. It looked something like this:
type T = {
[q: `a.${string}.b`]: string,
[q: `a.${string}.${string}`]: number
};
Which obviously shouldn't work.
The rest was confirmation bias and not looking for counter examples.
Sorry for wasting your time :).
(The first example contains a typo — it shouldn't be set to ["c", "d"] which doesn't type check indeed.)
Suggestion
Support multiple template literal string index signatures (initial support of which was added in TS 4.4 #44512):
🔍 Search Terms
template literal strings index signatures
✅ Viability Checklist
My suggestion meets these guidelines:
📃 Motivating Example & Use Cases
Same use cases as single template literal index signature, but more useful.
One example are objects containing queries for databases/APIs that support it (Firebase Firestore...) for validation purposes.
For example, this is what an API to update Firestore documents which validates update paths could look like:
Current best workaround is to define an overloaded function with
[path, value]
parameter pairs, but the downside is you can't supply a map or list of tuples (e.g. during class construction etc.).The text was updated successfully, but these errors were encountered: