question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Documentation example doesn't work with TypeScript

See original GitHub issue

Prerequisites

Environment check

  • I’m using the latest msw version
  • I’m using Node.js version 14 or higher

Browsers

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

// src/mocks/browser.js
import { setupWorker } from 'msw'
import { handlers } from './handlers'

// This configures a Service Worker with the given request handlers.
export const worker = setupWorker(...handlers)

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

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
gduliscouet-ubitransportcommented, Nov 25, 2022

@kettanaito I opened a PR to reuse the existing interface describing the class SetupWorkerApi. For me it is the only way to have it working on the consumer side (without the above workaround), but maybe you want to check the interface SetupWorkerApi is describing well enough the class SetupWorkerApi (at least TS it is matching according to TS)

2reactions
andykenwardcommented, Nov 24, 2022

@gduliscouet-ubitransport Adding the type annotation to the worker constant instead of using TypeScript inference allows me to output the definition file without errors.

import { setupWorker, type SetupWorkerApi } from 'msw';

export const worker:SetupWorkerApi = setupWorker(...[]);
Read more comments on GitHub >

github_iconTop Results From Across the Web

JSDoc Reference - TypeScript: Documentation
Documentation tags work in both TypeScript and JavaScript. ... @type can specify a union type — for example, something can be either a...
Read more >
Working with JavaScript in Visual Studio Code
Working with JavaScript. This topic describes some of the advanced JavaScript features supported by Visual Studio Code. Using the TypeScript language ...
Read more >
TypeScript - Cypress Documentation
You may have to restart your IDE's TypeScript server if the setup above does not appear to work. For example: VS Code (within...
Read more >
Using TypeScript - Expo Documentation
For example, you would rename App.js to App.tsx. Use the .tsx extension if the file includes React components (JSX). If the file did...
Read more >
TypeScript | IntelliJ IDEA Documentation - JetBrains
Verify TypeScript in the entire project · To open the Problems tool window, click the Inspections widget in the upper-right corner of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found