Skip to content

Instantly share code, notes, and snippets.

@ktsn
Created March 21, 2018 14:53
Show Gist options
  • Save ktsn/526ff676c5ce10d7de5c2ea4aebaea0a to your computer and use it in GitHub Desktop.
Save ktsn/526ff676c5ce10d7de5c2ea4aebaea0a to your computer and use it in GitHub Desktop.
Extract Vue component instance type
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);
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