I have this function
function someThing(someArg: Pick<HTMLElement, 'id' | 'style'>) {...}
However, I only want to add some styles to someArg.style, not all the style from CSSStyleDeclaration. Otherwise, the input of the function will be huge.
So I expect to have something like Pick from Partial<CSSStyleDeclaration> not Pick from CSSStyleDeclaration
How can I do that?
Since your type is more complicated than just
Picking some properties from an existing type, you might want to spell it out in its own interface:I'm using lookup types to make it clear that the
idandstyleproperties are related to those fromHTMLElement, but you could use juststringandPartial<CSSStyleDeclaration>instead.If you really need to use something like
Pickthat allows subproperties to bePartialyou can make a mapped type to do it, but I can't tell from your question if you need something programmatic.UPDATE
I guess you do want it to be programmatic (although for just two properties I wouldn't bother, myself) so here's a way to define
PickPartialso that you are picking fromPartialproperties instead of the properties themselves. I assume you don't need it to be recursive (you don't need each of the subproperties to themselves bePartial):Note that while this technically makes
idthe typePartial<string>, that is fine because mapped types do not modify primitives..Partial<string>is juststring. So the type ofsomeArgis the same as theSomeArginterface I spelled out above.Hope that helps. Good luck!