Skip to content

Commit

Permalink
Remove redundant assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
amvanbaren committed Nov 19, 2024
1 parent b10ba78 commit 60dd1f3
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
1 change: 0 additions & 1 deletion cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions cli/src/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { Readable } from 'stream';
import { Manifest } from './util';

async function bufferStream(stream: Readable): Promise<Buffer> {
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<Map<string, Buffer>> {
const zipfile = await new Promise<ZipFile>((c, e) =>
open(packagePath, { lazyEntries: true }, (err, zipfile) => (err ? e(err) : c(zipfile!)))
const zipfile = await new Promise<ZipFile>((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<string, Buffer>();

zipfile.once('close', () => c(result));
zipfile.once('close', () => resolve(result));

zipfile.readEntry();
zipfile.on('entry', (entry: Entry) => {
Expand All @@ -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();
});
Expand Down
4 changes: 2 additions & 2 deletions webui/src/extension-registry-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class ExtensionRegistryService {
getExtensionReadme(abortController: AbortController, extension: Extension): Promise<string> {
return sendRequest({
abortController,
endpoint: extension.files.readme!,
endpoint: extension.files.readme,
headers: { 'Accept': 'text/plain' },
followRedirect: true
});
Expand All @@ -127,7 +127,7 @@ export class ExtensionRegistryService {
getExtensionChangelog(abortController: AbortController, extension: Extension): Promise<string> {
return sendRequest({
abortController,
endpoint: extension.files.changelog!,
endpoint: extension.files.changelog,
headers: { 'Accept': 'text/plain' },
followRedirect: true
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const PublisherRevokeDialog: FunctionComponent<PublisherRevokeDialogProps
try {
setWorking(true);
const user = props.publisherInfo.user;
const result = await service.admin.revokePublisherContributions(abortController.current, user.provider!, user.loginName);
const result = await service.admin.revokePublisherContributions(abortController.current, user.provider as string, user.loginName);
if (isError(result)) {
throw result;
}
Expand Down
4 changes: 2 additions & 2 deletions webui/src/pages/extension-detail/extension-detail-reviews.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import React, { Fragment, FunctionComponent, ReactNode, useContext, useState, us
import { Box, Typography, Divider, Link } from '@mui/material';
import { MainContext } from '../../context';
import { toLocalTime } from '../../utils';
import { ExtensionReview, Extension, ExtensionReviewList, isEqualUser, isError } from '../../extension-registry-types';
import { ExtensionReview, Extension, ExtensionReviewList, isEqualUser, isError, UserData } from '../../extension-registry-types';
import { TextDivider } from '../../components/text-divider';
import { DelayedLoadIndicator } from '../../components/delayed-load-indicator';
import { ButtonWithProgress } from '../../components/button-with-progress';
Expand Down Expand Up @@ -67,7 +67,7 @@ export const ExtensionDetailReviews: FunctionComponent<ExtensionDetailReviewsPro
if (!context.user || !reviewList) {
return '';
}
const existingReview = reviewList.reviews.find(r => 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 <ButtonWithProgress
Expand Down
2 changes: 1 addition & 1 deletion webui/src/pages/user/user-namespace-extension-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const UserNamespaceExtensionListContainer: FunctionComponent<UserNamespac
const extensionUnfiltered = await Promise.all(
extensionsURLs.map((url: string) => getExtension(url))
);
const extensions = extensionUnfiltered.filter(e => !!e) as Extension[];
const extensions: Extension[] = extensionUnfiltered.filter(e => e != null);

setExtensions(extensions);
setLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions webui/src/server-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,15 @@ export async function sendRequest<Res>(req: ServerAPIRequest): Promise<Res> {

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':
return response.text() as Promise<any>;
case 'application/octet-stream':
return response.blob() as Promise<any>;
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';
Expand Down

0 comments on commit 60dd1f3

Please sign in to comment.