Relating keys and field constraints of a generic super type constructed with mapped type filtering out properties #47447
Labels
Needs Proposal
This issue needs a plan that clarifies the finer details of how it could be implemented.
Suggestion
An idea for TypeScript
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
🙂 Expected behavior
Reasoning
U
ofSuperType<T, C>
is also a key ofT
and its type extendsC
T[U]
should be allowed becauseU
iskeyof T
T[U]
should beC
becauseT[K]
extendsC
for any key inU
That is a very common task that you need to filter out some properties from a type. I saw people call it a subtype when in fact it is a supertype. But weirdly enough indexing be keys of the mapped type is not allowed. I saw it as a regression in a big codebase when upgraded to 4.5, but turned out the values were considered
any
. So now they're bounded tounknown
which is better but still cannot do much further.The text was updated successfully, but these errors were encountered: