From 700cb9dc86704e484befb7f7d9e03aaeb613c1da Mon Sep 17 00:00:00 2001 From: amvanbaren Date: Tue, 19 Nov 2024 20:21:48 +0200 Subject: [PATCH] Remove redundant assertions --- cli/src/main.ts | 1 - cli/src/registry.ts | 4 ++-- cli/src/zip.ts | 18 +++++++++--------- webui/src/extension-registry-service.ts | 4 ++-- .../publisher-revoke-dialog.tsx | 2 +- .../extension-detail-reviews.tsx | 4 ++-- .../user/user-namespace-extension-list.tsx | 2 +- webui/src/server-request.ts | 4 ++-- 8 files changed, 19 insertions(+), 20 deletions(-) diff --git a/cli/src/main.ts b/cli/src/main.ts index 94b806f34..52f1ba642 100644 --- a/cli/src/main.ts +++ b/cli/src/main.ts @@ -75,7 +75,6 @@ module.exports = function (argv: string[]): void { publish({ extensionFile, registryUrl, pat, targets: typeof target === 'string' ? [target] : target, packagePath: typeof packagePath === 'string' ? [packagePath] : packagePath, baseContentUrl, baseImagesUrl, yarn, preRelease, dependencies, skipDuplicate, packageVersion }) .then(results => { const reasons = results.filter(result => result.status === 'rejected') - .map(result => result as PromiseRejectedResult) .map(rejectedResult => rejectedResult.reason); if (reasons.length > 0) { diff --git a/cli/src/registry.ts b/cli/src/registry.ts index d0852901f..44eeefdbb 100644 --- a/cli/src/registry.ts +++ b/cli/src/registry.ts @@ -168,9 +168,9 @@ export class Registry { private getProtocol(url: URL) { if (url.protocol === 'https:') - return followRedirects.https as typeof https; + return followRedirects.https else - return followRedirects.http as typeof http; + return followRedirects.http } private getRequestOptions(method?: string, headers?: http.OutgoingHttpHeaders, maxBodyLength?: number): http.RequestOptions { diff --git a/cli/src/zip.ts b/cli/src/zip.ts index c8fb5a11f..6378f7be2 100644 --- a/cli/src/zip.ts +++ b/cli/src/zip.ts @@ -3,23 +3,23 @@ import { Readable } from 'stream'; import { Manifest } from './util'; async function bufferStream(stream: Readable): Promise { - return await new Promise((c, e) => { + return await new Promise((resolve, reject) => { const buffers: Buffer[] = []; stream.on('data', buffer => buffers.push(buffer)); - stream.once('error', e); - stream.once('end', () => c(Buffer.concat(buffers))); + stream.once('error', reject); + stream.once('end', () => resolve(Buffer.concat(buffers))); }); } export async function readZip(packagePath: string, filter: (name: string) => boolean): Promise> { - const zipfile = await new Promise((c, e) => - open(packagePath, { lazyEntries: true }, (err, zipfile) => (err ? e(err) : c(zipfile!))) + const zipfile = await new Promise((resolve, reject) => + open(packagePath, { lazyEntries: true }, (err, zipfile) => (err ? reject(err) : resolve(zipfile))) ); - return await new Promise((c, e) => { + return await new Promise((resolve, reject) => { const result = new Map(); - zipfile.once('close', () => c(result)); + zipfile.once('close', () => resolve(result)); zipfile.readEntry(); zipfile.on('entry', (entry: Entry) => { @@ -29,10 +29,10 @@ export async function readZip(packagePath: string, filter: (name: string) => boo zipfile.openReadStream(entry, (err, stream) => { if (err) { zipfile.close(); - return e(err); + return reject(err); } - bufferStream(stream!).then(buffer => { + bufferStream(stream).then(buffer => { result.set(name, buffer); zipfile.readEntry(); }); diff --git a/webui/src/extension-registry-service.ts b/webui/src/extension-registry-service.ts index ce369ee7e..6bb3144fb 100644 --- a/webui/src/extension-registry-service.ts +++ b/webui/src/extension-registry-service.ts @@ -118,7 +118,7 @@ export class ExtensionRegistryService { getExtensionReadme(abortController: AbortController, extension: Extension): Promise { return sendRequest({ abortController, - endpoint: extension.files.readme!, + endpoint: extension.files.readme, headers: { 'Accept': 'text/plain' }, followRedirect: true }); @@ -127,7 +127,7 @@ export class ExtensionRegistryService { getExtensionChangelog(abortController: AbortController, extension: Extension): Promise { return sendRequest({ abortController, - endpoint: extension.files.changelog!, + endpoint: extension.files.changelog, headers: { 'Accept': 'text/plain' }, followRedirect: true }); diff --git a/webui/src/pages/admin-dashboard/publisher-revoke-dialog.tsx b/webui/src/pages/admin-dashboard/publisher-revoke-dialog.tsx index ffb613aa4..2fce104c9 100644 --- a/webui/src/pages/admin-dashboard/publisher-revoke-dialog.tsx +++ b/webui/src/pages/admin-dashboard/publisher-revoke-dialog.tsx @@ -45,7 +45,7 @@ export const PublisherRevokeDialog: FunctionComponent isEqualUser(r.user, context.user!)); + const existingReview = reviewList.reviews.find(r => isEqualUser(r.user, context.user as UserData)); if (existingReview) { const localTime = toLocalTime(existingReview.timestamp); return getExtension(url)) ); - const extensions = extensionUnfiltered.filter(e => !!e) as Extension[]; + const extensions = extensionUnfiltered.filter(e => e != null) as Extension[]; setExtensions(extensions); setLoading(false); diff --git a/webui/src/server-request.ts b/webui/src/server-request.ts index ad51feab7..19bf1c170 100644 --- a/webui/src/server-request.ts +++ b/webui/src/server-request.ts @@ -66,7 +66,7 @@ export async function sendRequest(req: ServerAPIRequest): Promise { const response = await fetchBuilder(fetch, options)(req.endpoint, param); if (response.ok) { - switch (req.headers!['Accept']) { + switch (req.headers['Accept']) { case 'application/json': return response.json(); case 'text/plain': @@ -74,7 +74,7 @@ export async function sendRequest(req: ServerAPIRequest): Promise { case 'application/octet-stream': return response.blob() as Promise; default: - throw new Error(`Unsupported type ${req.headers!['Accept']}`); + throw new Error(`Unsupported type ${req.headers['Accept']}`); } } else if (response.status === 429) { const retrySeconds = response.headers.get('X-Rate-Limit-Retry-After-Seconds') || '0';