Repository navigation
Dynamic Super Types #11967
Copy link
Copy link
Open
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Description
Activity
HerringtonDarkholme commented
on Nov 1, 2016 ContributorMore actionsI wonder whether it is doable after #11929 landed. We can use overload + tuple syntax to mock it.
Something like
interface Model<IInstance> { findOne<K extends keyof IInstance>(options: [K]): { K: IInstance[K] }; findOne<K extends keyof IInstance, K1 extends keyof IInstance>(options: [K, K1]): { K: IInstance[K] } & {K1: IInstance[K1]}; // .... and more }
If we have variadic kinds in #5453, maybe dynamic super type can be supported directly?
Also,
K extends keyof Tseems to stand for one single string literal type to me. But in the return type it is used as a variadic kinds. May be...K extends keyof Tis better?Reacted by Aluan HaddadAlso, K extends keyof T seems to stand for one single string literal type to me. But in the return type it is used as a variadic kinds. May be ...K extends keyof T is better?
I stumbled upon this too. Though this problem might be a bit hard to solve perfectly.
- addedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on May 24, 2017 - addedAwaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScriptand removedNeeds InvestigationThis issue needs a team member to investigate its status.This issue needs a team member to investigate its status.
on Sep 20, 2019
Metadata
Metadata
Assignees
Labels
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScriptAn idea for TypeScript
Now, that #11929 is PR landed. I would really love to have some syntax to specify an arbitrary
super type of T. This can be especially helpful in creating strongly typed ORM database frameworks.Proposal
If
Kis constrained to be a key ofTi.eK extends keyof T. Then the syntax:Means spread the keys
Kand values ofTin{}.Example
Here is an example usage of an envisioned ORM framework: