Created
March 21, 2018 14:53
-
-
Save ktsn/526ff676c5ce10d7de5c2ea4aebaea0a to your computer and use it in GitHub Desktop.
Extract Vue component instance type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue, { VueConstructor } from "vue"; | |
declare function extractInstance<T extends Vue>(Ctor: VueConstructor<T>): T; | |
const Test = Vue.extend({ | |
data() { | |
return { | |
test: 123 | |
}; | |
} | |
}); | |
const test = extractInstance(Test); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue, { VueConstructor } from "vue"; | |
type VueInstance<T extends VueConstructor<any>> | |
= T extends VueConstructor<infer R> | |
? R | |
: never; | |
const Test = Vue.extend({ | |
data() { | |
return { | |
test: 123 | |
}; | |
} | |
}); | |
type TestType = VueInstance<typeof Test>; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment