Get the type of a react component prop in TypeScript

Julius Koronci
1 min readOct 24, 2019

--

I am writing this to myself because it is always a pain to google for how to get the type of a property on a 3rd party component. At work we use a 3rd party component library which often times doesn’t export types correctly. In my current case a Dropdown component accepts and array of DropdownItems but the type for items is not exported. Instead of writing it by hand we can do just this:

export type DropdownItems = JSX.LibraryManagedAttributes<
typeof DropdownMenu,
DropdownMenu['props']['items']
>;

This is in the documentation, anyone can google it but it always takes me 15 minutes and I somehow can’t remember it :D

--

--