Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
neilgibert1234 opened this issue Oct 14, 2020 · 0 comments

Comments

@neilgibert1234
Copy link

'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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant