Novel TS + vue error here.
There are a few guys asking similar questions on StackOverflow over the past 2 months. No answers there.
Here is my error:
src/bus/myEventBus.ts:11:31
TS2351: This expression is not constructable.
Type 'typeof import("C:/Users/Roland/2021one-coding-projects/Vue2021/yawn/hyrule-jobs/node_modules/vue/dist/vue")' has no construct signatures.
9 | // console.log("shdafhkasfksd", typeof x, x)
10 |
> 11 | export const myEventBus = new Vue(); // fixme: What is this? new Vue is totally correct.
Here is the charming source of the issue:
import Vue from 'vue';
export enum MyEventBusEvents {
MyTestEvent = 'my_test_event',
AddJob = "add_a_job",
}
export const myEventBus = new Vue();
Its like, ok well, maybe I can specify something different by switching to import { Vue } from 'vue-class-component'
and that will work. But then I get TS2339: Property '$on' does not exist on type 'Vue<unknown, {}, {}>'.
which is not what I want. I want to use $on later to make an event bus.
// where the $on error is from
import { myEventBus, MyEventBusEvents } from "../bus/myEventBus";
// ... snip ...
created() {
myEventBus.$on(
MyEventBusEvents.AddJob,
(title: string, loc: string, salary: number, ft: boolean) =>
this.addJob(title, loc, salary, ft)
);
},
The expectation is that new Vue()
sets up a new Vue instance so I can use it to send events back and forth using $emit
and $on
. This tutorial claims everything works fine using the code I copied from it. Apparently not.
Seems like it has potential but if the potential is real I'm doing it wrong. The answer is marked as correct but I don't know what good it does me, which is different from it necessarily being useless.
heres someone with similar issue in angular. Bad answer for me. Look:
ERROR in src/bus/myEventBus.ts:1:10
TS2305: Module '"../../node_modules/vue/dist/vue"' has no exported member 'Vue'.
> 1 | import { Vue } from 'vue'; // therefore adding { } does not help