-
-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: SubType #22
Comments
Hi there |
Can you elaborate on some real-world scenarios when this type would be useful? Preferably point to real code where it's used or where it could be used. This seems like a more powerful |
I have used a similar type. One use-case that I have is that I have a function that takes an object, and the key of a method to call. I only want the keys of the methods. This will work for that. |
@kaleb Would be great if you could include or link to some actual code using this pattern. |
@fabiospampinato @kainiedziela @WORMSS @uyeong @dylang Could use you feedback :) |
Maybe It looks like a pretty powerful type, but I'm not sure in what scenario I would use it 🤷♂. For instance just to give a quick example I'd personally rather write this: type Options = {
foo: number,
bar: boolean,
events: {
onFoo: Function,
onBar: Function
}
};
type JustMethods = Options['events']; Than this: type Options = {
foo: number,
bar: boolean,
onFoo: Function,
onBar: Function
};
type JustMethods = SubType<Options, Function>; There are definitely scenarios where I would use |
I think that could confuse users thinking it extracts all props and omits methods. I agree with the rest of Fabio's points. This seems like a powerful type that would be prone to misuse. |
Thanks for suggesting this type. However, I have decided to pass on it for reasons outlined in the discussion here. |
This does what I'd call a type filter, right? Or am I misunderstanding? Pick all props in |
@sindresorhus I'm pretty sure the utility being described in this issue is the same as |
Examples:
JustMethods
from #4 can be realized viaSubType
. But, as I understand,JustProps
can't. Maybe it will be possible after microsoft/TypeScript#29317The text was updated successfully, but these errors were encountered: