-
Notifications
You must be signed in to change notification settings - Fork 129
Typescript support #5
Comments
Since |
@ChrisShank Do you have a working setup for Typescript? If so, would you be willing to share it? I struggled with including support for |
@ChrisShank Thanks a lot, adding your changes worked like a charm 🎉 Now only vetur needs to remove the |
How To Add JSX Support |
@ChrisShank Thanks for the fork, it is exactly what I was looking for!! 😄 Idk if you saw this too but I was receiving this error in
But it seems to work fine if I change the routes to async functions like: routes: [
{ path: '/', component: async () => Home, name: 'home' },
{ path: '/about', component: async () => About, name: 'about' },
], |
@bekalshenoy JSX seems to be a work in progress right now... |
@onx2 Unfortunately I haven't been able to reproduce that error. I just updated the dependencies of my fork (most notably to |
@Timmitry here is a TS version of this repo. I did not use JSX, however. Just plain render functions. Just an idea. https://github.com/deemaxx/vue-next-webpack-typescript |
I get an error when I use a imported component as a type. import { defineComponent, ref } from "vue"
import HelloWorld from "./components/HelloWorld.vue"
export default defineComponent({
components: { HelloWorld },
setup() {
const componentRef = ref<HelloWorld | null>(null)
}
})
|
@janispritzkau |
I found a solution but it feels a bit like a hack. const componentRef = ref<InstanceType<typeof HelloWorld> | null>(null) @ChrisShank typeof only gives you the constructor type. |
I noticed that I was only able to directly use the components as a type because I was using class components. I also ran into another problem that you can't self reference a component, or have a child component, that has a type reference of it's parent which has the child component defined in it's components. |
I almost got it working using the following approach: <template>
<hello-world ref="hello">
</template>
<script lang="ts">
import { ComponentOptions } from 'vue';
import HelloWorld from "./components/HelloWorld.vue"
// helper function to attach type to a vue reference
function typesafeComponentRef<T>(elementRef: Element, vueComponent: T) {
type ExtractVueComponentType<X> = X extends ComponentOptions<any, infer Data, any, any, any, any> ? Data : never;
return elementRef as ExtractVueComponentType<typeof vueComponent>;
}
export default defineComponent({
setup(props, context) {
watchEffect(() => {
const helloWorld = typesafeComponentRef(context.refs.hello, HelloWorld)
// here code completion works in Intellij
// but the type of helloWorld is always `unknown`
const x = helloWorld.someDataVariable // autocompleted someDataVariable
...
});
}
});
</script> |
you can set this for vetur Also I create a project with vue3 and webpack, you can take a look here |
thx for your link can you translate your comments in the webpack.config in english please ? |
see vuejs/vue-next-webpack-preview#5 (comment) but we may lose the ability to locate the `.vue` file in `.ts`
I am adding Typescript and I am not certain what the shim for
*.vue
files should be? My best guess is:does anyone know if this is correct?
The text was updated successfully, but these errors were encountered: