Test generic type and see if its wrapped in a ref? #10467
Answered
by
LinusBorg
Ncage1974
asked this question in
Help/Questions
-
What would be the best way to test a generic type (typescript) to see if its wrapped in a ref? |
Beta Was this translation helpful? Give feedback.
Answered by
LinusBorg
Mar 6, 2024
Replies: 1 comment 1 reply
-
What do you want to do when "checking" this? can you give an example? In general, these things are usually done with an type X = T extends Ref ? SomeType : SomeOtherType
//with inference of the nested type:
type X = T extends Ref<infer U> ? SomeType<U> : SomeOtherType<U>
// extract the nested type:
type NestedT = T extends Ref<infer U> ? U : T
// Vue has a helper for that:
type NestedT = UnwrapRef<T> |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Ncage1974
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What do you want to do when "checking" this? can you give an example? In general, these things are usually done with an
extends
check in a conditional type, i.e.