comlink-loader icon indicating copy to clipboard operation
comlink-loader copied to clipboard

Using functions inside a typescript class - “TypeError: is not a function”

Open neil-gilbert opened this issue 5 years ago • 0 comments

'm trying to setup comlink in a typescript project but can't work out why this doesn't work.

My calling method/ class

import Mehs from "@/myTest.worker";

export default class TestCalling{``

public async callMyTestMethod(): Promise { const meh: Mehs = new Mehs();`` const ss: string = await meh.greet("Neil"); console.log(ss); } }` My test class/method

export default class TestWorker{ public async greet(subject: string): Promise { return new Promise((resolve) => { resolve(Hello, ${subject}!); }); } } This give me the following error : "TypeError: meh.greet is not a function"

However if i just export a function it works i.e.

export async function greet(subject: string): Promise { return new Promise((resolve) => { resolve(Hello, ${subject}!); }); } But i want to use a class as it may have multiple functions that i want to call. What am i doing wrong ?

neil-gilbert avatar Oct 14 '20 09:10 neil-gilbert