I’m wondering, is it possible to access a generic type for unrelated type declarations?
For example, I just wrote this beast just to access the T
of a React.Context<T>
:
import { nominalTypeHack } from 'prop-types'
import { MyContext } from '../../context/myContext';
NonNullable<NonNullable<NonNullable<typeof MyContext.Provider.propTypes>['value']>[typeof nominalTypeHack]>['type']
I know I could just declare T
explicitely and use it when creating the context and refer to it at all other places, but maybe there’s a more dynamic way to achieve that, besides drilling to to the place where the generic is eventually used in a property declaration?
I apologize if this question has been asked before, but the search results are crowded with questions about how to access a generic type at runtime, which is not what I’m aiming at.