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

SharedWorker constructor does not accept URL #43689

Closed
johannesf95 opened this issue Apr 15, 2021 · 3 comments
Closed

SharedWorker constructor does not accept URL #43689

johannesf95 opened this issue Apr 15, 2021 · 3 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@johannesf95
Copy link

johannesf95 commented Apr 15, 2021

Bug Report

πŸ”Ž Search Terms

SharedWorker constructor, Worker URL

⏯ Playground Link

Playground link with relevant code

πŸ’» Code

new SharedWorker(new URL(""));

πŸ™ Actual behavior

SharedWorker constructor only accepts string but not URL.

[ts] Argument of type 'URL' is not assignable to parameter of type 'string'.

πŸ™‚ Expected behavior

SharedWorker constructor should accept string or URL like Worker 28397

Since webpack changed its supported syntax for Worker initialization to pass a URL, which also applies to SharedWorker, this missing type became more relevant.

@andrewbranch
Copy link
Member

Feel free to open a PR at https://github.com/Microsoft/TSJS-lib-generator.

@andrewbranch andrewbranch added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this labels Apr 16, 2021
@andrewbranch andrewbranch added this to the Backlog milestone Apr 16, 2021
@TimvdLippe
Copy link
Contributor

This appears to be another instance of #43066 (comment)

@FDiskas
Copy link

FDiskas commented May 13, 2023

This was fixed starting from v4.4.4
Works for me

const worker = new SharedWorker(new URL('./worker.ts', import.meta.url), {
  type: "module",
});

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": [
      "WebWorker",
      "ES2020",
      "DOM",
      "DOM.Iterable"
    ],
    "skipLibCheck": true,
    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    /* Linting */
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
  },
  "include": [
    "src"
  ]
}

typescript@5.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants