Skip to content

Commit

Permalink
chore: remove ts-ignores. force ts-expect-error (#1883)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcosta7 committed Nov 24, 2023
1 parent 657edd8 commit e078e91
Show file tree
Hide file tree
Showing 32 changed files with 226 additions and 217 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
'plugin:prettier/recommended',
],
rules: {
'@typescript-eslint/prefer-ts-expect-error': 2,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/ban-ts-comment': 0,
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/compat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ jobs:
- name: Install dependencies
run: pnpm install

- name: Install TypeScript ${{ matrix.ts }}
run: pnpm add typescript@${{ matrix.ts }}

- name: Build
run: pnpm build

- name: Install TypeScript ${{ matrix.ts }}
run: pnpm add typescript@${{ matrix.ts }}

- name: Typings tests
run: |
pnpm tsc --version
Expand Down
9 changes: 1 addition & 8 deletions config/plugins/esbuild/copyWorkerPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,7 @@ const SERVICE_WORKER_OUTPUT_PATH = path.resolve(
)

function getChecksum(contents: string): string {
const { code } = minify(
contents,
{},
{
// @ts-ignore "babel-minify" has no type definitions.
comments: false,
},
)
const { code } = minify(contents, {}, { comments: false })

return crypto.createHash('md5').update(code, 'utf8').digest('hex')
}
Expand Down
13 changes: 13 additions & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,16 @@ declare module '@bundled-es-modules/statuses' {
import * as statuses from 'statuses'
export default statuses
}

declare module 'babel-minify' {
export default function babelMinify(
code: string,
opts: Record<string, any>,
babelOpts: Record<string, any>,
): { code: string }
}

declare module '@bundled-es-modules/js-levenshtein' {
import levenshtein from 'js-levenshtein'
export default levenshtein
}
9 changes: 1 addition & 8 deletions src/browser/setupWorker/start/utils/createMessageChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ export class WorkerChannel {
...rest: WorkerChannelEventsMap[Event]
): void {
const [data, transfer] = rest
this.port.postMessage(
{ type: event, data },
{
// @ts-ignore ReadableStream can be transferred
// but TypeScript doesn't acknowledge that.
transfer,
},
)
this.port.postMessage({ type: event, data }, { transfer })
}
}
17 changes: 9 additions & 8 deletions src/core/utils/internal/pipeEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,19 @@ export function pipeEvents<Events extends EventMap>(
source: Emitter<Events>,
destination: Emitter<Events>,
): void {
const rawEmit = source.emit
const rawEmit: typeof source.emit & { _isPiped?: boolean } = source.emit

// @ts-ignore
if (rawEmit._isPiped) {
return
}

source.emit = function (event, ...data) {
destination.emit(event, ...data)
return rawEmit.call(this, event, ...data)
}
const sourceEmit: typeof source.emit & { _isPiped?: boolean } =
function sourceEmit(this: typeof source, event, ...data) {
destination.emit(event, ...data)
return rawEmit.call(this, event, ...data)
}

sourceEmit._isPiped = true

// @ts-ignore
source.emit._isPiped = true
source.emit = sourceEmit
}
1 change: 0 additions & 1 deletion src/core/utils/request/onUnhandledRequest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-ignore
import jsLevenshtein from '@bundled-es-modules/js-levenshtein'
import { RequestHandler, HttpHandler, GraphQLHandler } from '../..'
import {
Expand Down
13 changes: 7 additions & 6 deletions test/browser/graphql-api/anonymous-operation.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { setupWorker } from 'msw/browser'
const worker = setupWorker()
worker.start()

// @ts-ignore
window.msw = {
worker,
graphql,
HttpResponse,
}
Object.assign(window, {
msw: {
worker,
graphql,
HttpResponse,
},
})
35 changes: 17 additions & 18 deletions test/browser/graphql-api/response-patching.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,22 @@ const worker = setupWorker(
}),
)

// @ts-ignore
window.msw = {
registration: worker.start(),
}

// @ts-ignore
window.dispatchGraphQLQuery = (uri: string) => {
const client = createGraphQLClient({ uri })
Object.assign(window, {
msw: {
registration: worker.start(),
},
dispatchGraphQLQuery: (uri: string) => {
const client = createGraphQLClient({ uri })

return client({
query: gql`
query GetUser {
user {
firstName
lastName
return client({
query: gql`
query GetUser {
user {
firstName
lastName
}
}
}
`,
})
}
`,
})
},
})
2 changes: 1 addition & 1 deletion test/browser/msw-api/exception-handling.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { setupWorker } from 'msw/browser'

const worker = setupWorker(
http.get('https://api.github.com/users/:username', () => {
// @ts-ignore
// @ts-expect-error nonExisting should not be defined
nonExisting()
return
}),
Expand Down
15 changes: 8 additions & 7 deletions test/browser/msw-api/req/passthrough.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ const worker = setupWorker(

worker.start()

// @ts-ignore
window.msw = {
worker,
http,
passthrough,
HttpResponse,
}
Object.assign(window, {
msw: {
worker,
http,
passthrough,
HttpResponse,
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ const worker = setupWorker(

worker.start()

// @ts-ignore
window.worker = worker
Object.assign(window, { worker })
4 changes: 1 addition & 3 deletions test/browser/msw-api/setup-worker/input-validation.mocks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { http, HttpResponse } from 'msw'
import { setupWorker } from 'msw/browser'

// The next line will be ignored because we want to test that an Error
// should be trown when `setupWorker` parameters are not valid
//@ts-ignore
//@ts-expect-error invalid parameter provided to setupWorker so we can validate it throws
const worker = setupWorker([
http.get('/book/:bookId', function originalResolver() {
return HttpResponse.json({ title: 'Original title' })
Expand Down
15 changes: 8 additions & 7 deletions test/browser/msw-api/setup-worker/life-cycle-events/on.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ worker.events.on('request:unhandled', ({ request, requestId }) => {
)
})

const requestEndListner: (
const requestEndListener: (
...args: LifeCycleEventsMap['request:end']
) => void = ({ request, requestId }) => {
console.warn(`[request:end] ${request.method} ${request.url} ${requestId}`)
}

worker.events.on('request:end', requestEndListner)
worker.events.on('request:end', requestEndListener)

worker.events.on('response:mocked', async ({ response, requestId }) => {
const body = await response.clone().text()
Expand All @@ -55,8 +55,9 @@ worker.start({
onUnhandledRequest: 'bypass',
})

// @ts-ignore
window.msw = {
worker,
requestEndListner,
}
Object.assign(window, {
msw: {
worker,
requestEndListener,
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { test, expect } from '../../../playwright.extend'
declare namespace window {
export const msw: {
worker: SetupWorkerApi
requestEndListner: any
requestEndListener: any
}
}

Expand All @@ -21,7 +21,7 @@ test('removes a listener by the event name', async ({

await page.evaluate(() => {
const { msw } = window
msw.worker.events.removeListener('request:end', msw.requestEndListner)
msw.worker.events.removeListener('request:end', msw.requestEndListener)
})

const url = makeUrl('/user')
Expand Down
13 changes: 7 additions & 6 deletions test/browser/msw-api/setup-worker/listHandlers.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ const worker = setupWorker(

worker.start()

// @ts-ignore
window.msw = {
worker,
http,
graphql,
}
Object.assign(window, {
msw: {
worker,
http,
graphql,
},
})
9 changes: 5 additions & 4 deletions test/browser/msw-api/setup-worker/start/error.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const worker = setupWorker(
}),
)

// @ts-ignore
window.msw = {
worker,
}
Object.assign(window, {
msw: {
worker,
},
})
39 changes: 20 additions & 19 deletions test/browser/msw-api/setup-worker/start/find-worker.error.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ const worker = setupWorker(
}),
)

// @ts-ignore
window.msw = {
registration: worker
.start({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
findWorker: (scriptURL, _mockServiceWorkerUrl) => {
return scriptURL.includes('some-bad-filename-that-does-not-exist.js')
},
})
.then((registration) => {
console.log('Registration Promise resolved')
// This will throw as as there is no instance returned with a non-matching worker name.
return registration?.constructor.name
})
.catch((error) => {
console.error('Error - no worker instance after starting', error)
throw error
}),
}
Object.assign(window, {
msw: {
registration: worker
.start({
// eslint-disable-next-line @typescript-eslint/no-unused-vars
findWorker: (scriptURL, _mockServiceWorkerUrl) => {
return scriptURL.includes('some-bad-filename-that-does-not-exist.js')
},
})
.then((registration) => {
console.log('Registration Promise resolved')
// This will throw as as there is no instance returned with a non-matching worker name.
return registration?.constructor.name
})
.catch((error) => {
console.error('Error - no worker instance after starting', error)
throw error
}),
},
})
29 changes: 15 additions & 14 deletions test/browser/msw-api/setup-worker/start/find-worker.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ const worker = setupWorker(
}),
)

// @ts-ignore
window.msw = {
registration: worker
.start({
// This is the default matching behavior if left unspecified.
findWorker(scriptURL, mockServiceWorkerUrl) {
return scriptURL === mockServiceWorkerUrl
},
})
.then((registration) => {
console.log('Registration Promise resolved', registration)
return registration?.constructor.name
}),
}
Object.assign(window, {
msw: {
registration: worker
.start({
// This is the default matching behavior if left unspecified.
findWorker(scriptURL, mockServiceWorkerUrl) {
return scriptURL === mockServiceWorkerUrl
},
})
.then((registration) => {
console.log('Registration Promise resolved', registration)
return registration?.constructor.name
}),
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ worker.start({
onUnhandledRequest: 'warn',
})

// @ts-ignore
window.msw = {
worker,
http,
graphql,
}
Object.assign(window, {
msw: {
worker,
http,
graphql,
},
})
15 changes: 8 additions & 7 deletions test/browser/msw-api/setup-worker/start/quiet.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ const worker = setupWorker(
}),
)

// @ts-ignore
window.msw = {
registration: worker.start({
// Disable logging of matched requests into browser's console
quiet: true,
}),
}
Object.assign(window, {
msw: {
registration: worker.start({
// Disable logging of matched requests into browser's console
quiet: true,
}),
},
})
Loading

0 comments on commit e078e91

Please sign in to comment.