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
It is not possible to create a type, that has an index type + properties of a different type:
typeA{[key: string]: number;
foo: string}// error
However, this case is not unsual and should be considered.
To achive that, it is needed to remove certain keys from the index.
In the definition above, this could simply be done by removing all defined keys (in this caseonly "foo") from the index automatically.
Removing keys from the index is also useful if you wanna add attributes with different type:
(a similar issue for that example is here: #49867)
π Motivating Example
I guess I cramped all infos into the summary, I am sorry
π» Use Cases
Atm, mixing index types with other types is almost impossible. If you know, that you get an object that has certain typed values but also know that ONE keys is always set and different, you cannot type this properly atm because you cant have an index type + a different other key.
Activity
MartinJohns commentedon Dec 19, 2022
Duplicate of #4196 / #29317. The type system can't represent types like "A, except of B".
jcalz commentedon Dec 19, 2022
Also duplicate of #17867
typescript-bot commentedon Dec 22, 2022
This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.