How to use web worker in typescript cc 3.5.1?

Hi everyone, I am having problem using web worker in cocos.
I have file a.ts and file worker.ts. How can i import file a.ts into worker.ts ? I try to use importScripts(a.js) but it’s not work because importScripts is not defined.

I might be off with what you’re asking but if you want to import another script I’ve done it like this.

import { yourscript } from './a';

Then you can call like:

yourscript.someVariable

I have file main.ts like this

import  MyWorker from `../MyWorker'
 const code = MyWorker.toString();
    const blob = new Blob([`(${code})()`]);
    const worker = new Worker(URL.createObjectURL(blob));

file MyWorker like this

import AnotherFile from '.../AnotherFile';

export default () => {
  console.log(test, AnotherFile); // error here
};

I’m not sure why your importing the script and then converting to a string? Is the response from the script only going to be as a string? Even then I’d expect a function would need to be called from the myWorker script, then convert the response to a string?

I.e

Const code = myWorker.myFunction().toString();

This is presuming you have more to your script then outputting the console.log. which if that is your current goal then console log won’t work as you are converting to a string (or atleast I wouldn’t think so as it is no longer an object). I’m guessing there’s more to the myWorker script as I would presume so as you can’t convert a console log to a blob either.