Skip to content

Is there API to get type of a context? #457

Answered by danielpza
zhaoyao91 asked this question in Q&A
Discussion options

You must be logged in to vote

Perhaps this is what you want https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#inferring-within-conditional-types

type ContextType<T extends Context<any>> = T extends Context<infer R> ? R : never;

type MyContext = Context<number>

const value: ContextType<MyContext> // number

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@zhaoyao91
Comment options

Comment options

You must be logged in to vote
2 replies
@zhaoyao91
Comment options

@ryansolid
Comment options

Answer selected by zhaoyao91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants