-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
Documentation example doesn't work with TypeScript #1454
Comments
I have the same issue (with Here is an explaination of the warning from microsoft/TypeScript#30355:
I'm trying this workaround in the meanwhile, taken from here (not sure I'm doing it well, I didn't check everything) import { setupWorker, type SetupWorkerApi } from 'msw'
import { handlers } from './handlers'
type SetupWorkerApiWithoutPrivate = Omit<SetupWorkerApi, never>
// This configures a Service Worker with the given request handlers.
export const worker = setupWorker(...handlers) as SetupWorkerApiWithoutPrivate |
I'm not sure how this is related to MSW as we don't emit anonymous classes. You can see that the
This must be something else. The library builds without issues for me on TS 4.8 but I haven't used it in an example project to verify the consumer's side. |
You are right, the issue I shared is talking about an "anonymous class". But here you can see the same TS error with a named class: microsoft/TypeScript#17293. From what I understand, you should be able to do that, but you cannot due to some limitations in the declaration file creation. See this issue regrouping all the issues with .d.ts declaration files: microsoft/TypeScript#35822. From what I see, the only solution seems to not use You can launch the repro of @filipw01 to see the error on consumer side: https://stackblitz.com/edit/node-ifch93?file=index.ts |
@gduliscouet-ubitransport Adding the type annotation to the import { setupWorker, type SetupWorkerApi } from 'msw';
export const worker:SetupWorkerApi = setupWorker(...[]); |
I confrim ! Thank you @andykenward for sharing. In fact I realised that:
|
@kettanaito I opened a PR to reuse the existing interface describing the class |
Thanks for adding the fix, @gduliscouet-ubitransport! I left a few comments on how we could export both the type and the class and fix this issue. Hopefully, that direction would also work. |
Released: v0.49.1 🎉This has been released in v0.49.1! Make sure to always update to the latest version ( Predictable release automation by @ossjs/release. |
Prerequisites
Environment check
msw
versionBrowsers
No response
Reproduction repository
https://stackblitz.com/edit/node-ifch93?file=index.ts
Reproduction steps
Use documentation example with typescript https://mswjs.io/docs/getting-started/integrate/browser#configure-worker
Current behavior
Typescript throws multiple
TS4094: Property 'SOMETHING' of exported class expression may not be private or protected.
Expected behavior
I expect typescript to be fine with that
The text was updated successfully, but these errors were encountered: