With given tsconfig.json,
{
"compilerOptions": {
"lib": ["es2015", "dom"]
},
"files": [
"./project1/tstut.ts",
"./project1/worker.ts"
]
}
For below worker code(./project1/worker.ts),
window.addEventListener('message', (e) => {
// console.log(e)
if(e.data === 'do some work'){
console.log('Worker is about to start some work');
let count: number =0;
for(let i: number=0; i<1000; i++){
count += i;
}
window.postMessage({message:count});
}
})
Instead of self, window object is used in TS worker code. JS allows syntax self.postMessage({message: count})
How to resolve below error for postMessage()?
Expecting 2-3 arguments, but got 1
According to mdn it looks like the second argument should always be provided?
@andy-ms Code is on https://shamhub.github.io/ you can see webworker example there
Do I need to mention second argument as "https://shamhub.github.io/" or "https://shamhub.github.io/project1"?
I don't know, but it doesn't seem like this is a compiler bug, maybe look for a help forum somewhere?
Hello,
I have got the exact same issue. The error appears on the line postMessage() call while compiling a WebWorker.ts file in Angular 6. There is no error on the browser side though, the WebWorker works as expected.
Any help would be appreciated. Regards
Automatically closing this issue for housekeeping purposes. The issue labels indicate that it is unactionable at the moment or has already been addressed.
It's 2019 and I still get the error. The compiler is confusing the one of the web worker object with the one of the window object.
2020, still.
May 2020, still.
June 2020 still get the error
July 2020, found this on google
Nov 2020, still
Most helpful comment
July 2020, found this on google