1
0
forked from mirror/misskey

refactor(sw): Typecheck the service worker (#9314)

* Typecheck the service worker

Currently the service worker build never typechecks, since esbuild and typescript-eslint don't do such job.

esbuild: https://esbuild.github.io/content-types/#typescript

>However, esbuild does not do any type checking so you will still need to run tsc -noEmit in parallel with esbuild to check types. This is not something esbuild does itself.

typescript-eslint: https://typescript-eslint.io/linting/troubleshooting#why-dont-i-see-typescript-errors-in-my-eslint-output

>TypeScript's compiler (or whatever your build chain may be) is specifically designed and built to validate the correctness of your codebase. Our tooling does not reproduce the errors that TypeScript provides, because doing so would slow down the lint run [1], and duplicate the errors that TypeScript already outputs for you.

Adding this step adds tons of TS errors 😱

* Override lib-webworker with service worker
This commit is contained in:
Kagami Sascha Rosylight 2022-12-12 22:20:35 +09:00 committed by GitHub
parent 0294555e2b
commit cfd7cf0f1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 16 deletions

View File

@ -4,7 +4,7 @@
"scripts": { "scripts": {
"watch": "node build.js watch", "watch": "node build.js watch",
"build": "node build.js", "build": "node build.js",
"lint": "eslint --quiet src/**/*.ts" "lint": "tsc --noEmit && eslint --quiet src/**/*.ts"
}, },
"dependencies": { "dependencies": {
"esbuild": "^0.14.42", "esbuild": "^0.14.42",
@ -13,7 +13,9 @@
}, },
"devDependencies": { "devDependencies": {
"@typescript-eslint/parser": "^5.45.0", "@typescript-eslint/parser": "^5.45.0",
"@typescript/lib-webworker": "npm:@types/serviceworker@^0.0.58",
"eslint": "^8.16.0", "eslint": "^8.16.0",
"eslint-plugin-import": "^2.26.0" "eslint-plugin-import": "^2.26.0",
"typescript": "4.9.4"
} }
} }

View File

@ -1,11 +1,6 @@
/* /*
* Notification manager for SW * Notification manager for SW
*/ */
// TODO: remove this declaration when https://github.com/microsoft/TypeScript/issues/11781 closes
// eslint-disable-next-line no-var
declare var self: ServiceWorkerGlobalScope;
import { swLang } from '@/scripts/lang'; import { swLang } from '@/scripts/lang';
import { cli } from '@/scripts/operations'; import { cli } from '@/scripts/operations';
import { pushNotificationDataMap } from '@/types'; import { pushNotificationDataMap } from '@/types';

View File

@ -2,11 +2,6 @@
* Operations * Operations
* *
*/ */
// TODO: remove this declaration when https://github.com/microsoft/TypeScript/issues/11781 closes
// eslint-disable-next-line no-var
declare var self: ServiceWorkerGlobalScope;
import * as Misskey from 'misskey-js'; import * as Misskey from 'misskey-js';
import { SwMessage, swMessageOrderType } from '@/types'; import { SwMessage, swMessageOrderType } from '@/types';
import { acct as getAcct } from '@/filters/user'; import { acct as getAcct } from '@/filters/user';

View File

@ -1,7 +1,3 @@
// TODO: remove this declaration when https://github.com/microsoft/TypeScript/issues/11781 closes
// eslint-disable-next-line no-var
declare var self: ServiceWorkerGlobalScope;
import { createEmptyNotification, createNotification } from '@/scripts/create-notification'; import { createEmptyNotification, createNotification } from '@/scripts/create-notification';
import { swLang } from '@/scripts/lang'; import { swLang } from '@/scripts/lang';
import { swNotificationRead } from '@/scripts/notification-read'; import { swNotificationRead } from '@/scripts/notification-read';

View File

@ -3009,6 +3009,13 @@ __metadata:
languageName: node languageName: node
linkType: hard linkType: hard
"@typescript/lib-webworker@npm:@types/serviceworker@^0.0.58":
version: 0.0.58
resolution: "@types/serviceworker@npm:0.0.58"
checksum: d6aa73d02854968ccaa0fb7f1aafb30b202870dc15b9d09e3ee8fe8131ffc26d521c1e56b5b030f39fba329143a32b2fa88351d57df3ae5aa29498384a251946
languageName: node
linkType: hard
"@vitejs/plugin-vue@npm:4.0.0": "@vitejs/plugin-vue@npm:4.0.0":
version: 4.0.0 version: 4.0.0
resolution: "@vitejs/plugin-vue@npm:4.0.0" resolution: "@vitejs/plugin-vue@npm:4.0.0"
@ -15791,11 +15798,13 @@ __metadata:
resolution: "sw@workspace:packages/sw" resolution: "sw@workspace:packages/sw"
dependencies: dependencies:
"@typescript-eslint/parser": ^5.45.0 "@typescript-eslint/parser": ^5.45.0
"@typescript/lib-webworker": "npm:@types/serviceworker@^0.0.58"
esbuild: ^0.14.42 esbuild: ^0.14.42
eslint: ^8.16.0 eslint: ^8.16.0
eslint-plugin-import: ^2.26.0 eslint-plugin-import: ^2.26.0
idb-keyval: ^6.1.0 idb-keyval: ^6.1.0
misskey-js: 0.0.14 misskey-js: 0.0.14
typescript: 4.9.4
languageName: unknown languageName: unknown
linkType: soft linkType: soft