Skip to content

Instantly share code, notes, and snippets.

@wonderful-panda
Created October 17, 2017 02:20
Show Gist options
  • Select an option

  • Save wonderful-panda/1f8d7d190805bfebd230fd52cc4b945f to your computer and use it in GitHub Desktop.

Select an option

Save wonderful-panda/1f8d7d190805bfebd230fd52cc4b945f to your computer and use it in GitHub Desktop.
apply additional types to vue component (for vue 2.5)
import Vue, { VNode, VNodeChildrenArrayContents } from "vue";
import { VueConstructor } from "vue/types/vue";
export function vueWith<T>(): VueConstructor<Vue & T> {
return Vue as any;
}
export const TestComponent = vueWith<{
$refs: { test: HTMLDivElement },
$scopedSlots: {
default: (props: { text: string }) => VNodeChildrenArrayContents
}
}>().extend({
name: "TestComponent",
props: {
text: String
},
methods: {
hello(): void {
const html = this.$refs.test.innerHTML;
console.log(html);
}
},
render(h): VNode {
return h("div", { on: { click: this.hello }, ref: "test" },
this.$scopedSlots.default({ text: this.text })
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment