1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

remove unnecessary | undefined types from the exactOptionalFieldTypes experiment

Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
Sebastian Malton 2022-05-05 09:26:35 -04:00
parent a1afd425b8
commit b9ea2098b2
12 changed files with 40 additions and 43 deletions

View File

@ -93,8 +93,8 @@ export interface DeploymentSpec {
template: { template: {
metadata: { metadata: {
creationTimestamp?: string; creationTimestamp?: string;
labels: Record<string, string | undefined>; labels: Partial<Record<string, string>>;
annotations?: Record<string, string | undefined>; annotations?: Partial<Record<string, string>>;
}; };
spec: PodSpec; spec: PodSpec;
}; };

View File

@ -93,8 +93,8 @@ export interface HorizontalPodAutoscalerStatus {
} }
interface MetricCurrentTarget { interface MetricCurrentTarget {
current?: string | undefined; current?: string;
target?: string | undefined; target?: string;
} }
export class HorizontalPodAutoscaler extends KubeObject<HorizontalPodAutoscalerStatus, HorizontalPodAutoscalerSpec, KubeObjectScope.Namespace> { export class HorizontalPodAutoscaler extends KubeObject<HorizontalPodAutoscalerStatus, HorizontalPodAutoscalerSpec, KubeObjectScope.Namespace> {

View File

@ -713,8 +713,8 @@ export interface PodSpec {
imagePullSecrets?: LocalObjectReference[]; imagePullSecrets?: LocalObjectReference[];
initContainers?: PodContainer[]; initContainers?: PodContainer[];
nodeName?: string; nodeName?: string;
nodeSelector?: Record<string, string | undefined>; nodeSelector?: Partial<Record<string, string>>;
overhead?: Record<string, string | undefined>; overhead?: Partial<Record<string, string>>;
preemptionPolicy?: string; preemptionPolicy?: string;
priority?: number; priority?: number;
priorityClassName?: string; priorityClassName?: string;

View File

@ -84,7 +84,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
async getResponse<Query>( async getResponse<Query>(
path: string, path: string,
params?: ParamsAndQuery<Params, Query> | undefined, params?: ParamsAndQuery<Params, Query>,
init: RequestInit = {}, init: RequestInit = {},
): Promise<Response> { ): Promise<Response> {
let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`; let reqUrl = `${this.config.serverAddress}${this.config.apiBase}${path}`;
@ -110,7 +110,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
get<OutData = Data, Query = QueryParams>( get<OutData = Data, Query = QueryParams>(
path: string, path: string,
params?: ParamsAndQuery<Params, Query> | undefined, params?: ParamsAndQuery<Params, Query>,
reqInit: RequestInit = {}, reqInit: RequestInit = {},
) { ) {
return this.request<OutData, Query>(path, params, { ...reqInit, method: "get" }); return this.request<OutData, Query>(path, params, { ...reqInit, method: "get" });
@ -118,7 +118,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
post<OutData = Data, Query = QueryParams>( post<OutData = Data, Query = QueryParams>(
path: string, path: string,
params?: ParamsAndQuery<Params, Query> | undefined, params?: ParamsAndQuery<Params, Query>,
reqInit: RequestInit = {}, reqInit: RequestInit = {},
) { ) {
return this.request<OutData, Query>(path, params, { ...reqInit, method: "post" }); return this.request<OutData, Query>(path, params, { ...reqInit, method: "post" });
@ -126,7 +126,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
put<OutData = Data, Query = QueryParams>( put<OutData = Data, Query = QueryParams>(
path: string, path: string,
params?: ParamsAndQuery<Params, Query> | undefined, params?: ParamsAndQuery<Params, Query>,
reqInit: RequestInit = {}, reqInit: RequestInit = {},
) { ) {
return this.request<OutData, Query>(path, params, { ...reqInit, method: "put" }); return this.request<OutData, Query>(path, params, { ...reqInit, method: "put" });
@ -134,7 +134,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
patch<OutData = Data, Query = QueryParams>( patch<OutData = Data, Query = QueryParams>(
path: string, path: string,
params?: (ParamsAndQuery<Omit<Params, "data">, Query> & { data?: Patch | PartialDeep<Data> }) | undefined, params?: (ParamsAndQuery<Omit<Params, "data">, Query> & { data?: Patch | PartialDeep<Data> }),
reqInit: RequestInit = {}, reqInit: RequestInit = {},
) { ) {
return this.request<OutData, Query>(path, params, { ...reqInit, method: "patch" }); return this.request<OutData, Query>(path, params, { ...reqInit, method: "patch" });
@ -142,7 +142,7 @@ export class JsonApi<Data = JsonApiData, Params extends JsonApiParams<Data> = Js
del<OutData = Data, Query = QueryParams>( del<OutData = Data, Query = QueryParams>(
path: string, path: string,
params?: ParamsAndQuery<Params, Query> | undefined, params?: ParamsAndQuery<Params, Query>,
reqInit: RequestInit = {}, reqInit: RequestInit = {},
) { ) {
return this.request<OutData, Query>(path, params, { ...reqInit, method: "delete" }); return this.request<OutData, Query>(path, params, { ...reqInit, method: "delete" });

View File

@ -8,11 +8,11 @@
import { splitArray } from "../utils"; import { splitArray } from "../utils";
export interface IKubeApiLinkRef { export interface IKubeApiLinkRef {
apiPrefix?: string | undefined; apiPrefix?: string;
apiVersion: string; apiVersion: string;
resource: string; resource: string;
name?: string | undefined; name?: string;
namespace?: string | undefined; namespace?: string;
} }
export interface IKubeApiParsed extends IKubeApiLinkRef { export interface IKubeApiParsed extends IKubeApiLinkRef {

View File

@ -105,18 +105,18 @@ export interface IgnoredKubeApiOptions {
} }
export interface KubeApiQueryParams { export interface KubeApiQueryParams {
watch?: boolean | number | undefined; watch?: boolean | number;
resourceVersion?: string | undefined; resourceVersion?: string;
timeoutSeconds?: number | undefined; timeoutSeconds?: number;
limit?: number | undefined; // doesn't work with ?watch limit?: number; // doesn't work with ?watch
continue?: string | undefined; // might be used with ?limit from second request continue?: string; // might be used with ?limit from second request
labelSelector?: string | string[] | undefined; // restrict list of objects by their labels, e.g. labelSelector: ["label=value"] labelSelector?: string | string[]; // restrict list of objects by their labels, e.g. labelSelector: ["label=value"]
fieldSelector?: string | string[] | undefined; // restrict list of objects by their fields, e.g. fieldSelector: "field=name" fieldSelector?: string | string[]; // restrict list of objects by their fields, e.g. fieldSelector: "field=name"
} }
export interface KubeApiListOptions { export interface KubeApiListOptions {
namespace?: string | undefined; namespace?: string;
reqInit?: RequestInit | undefined; reqInit?: RequestInit;
} }
export interface IKubePreferredVersion { export interface IKubePreferredVersion {
@ -268,13 +268,13 @@ export type KubeApiWatchCallback<T extends KubeJsonApiData = KubeJsonApiData> =
export interface KubeApiWatchOptions<Object extends KubeObject<any, any, KubeObjectScope>, Data extends KubeJsonApiDataFor<Object>> { export interface KubeApiWatchOptions<Object extends KubeObject<any, any, KubeObjectScope>, Data extends KubeJsonApiDataFor<Object>> {
namespace: string; namespace: string;
callback?: KubeApiWatchCallback<Data> | undefined; callback?: KubeApiWatchCallback<Data>;
abortController?: AbortController | undefined; abortController?: AbortController;
watchId?: string | undefined; watchId?: string;
retry?: boolean | undefined; retry?: boolean;
// timeout in seconds // timeout in seconds
timeout?: number | undefined; timeout?: number;
} }
export type KubeApiPatchType = "merge" | "json" | "strategic"; export type KubeApiPatchType = "merge" | "json" | "strategic";
@ -296,7 +296,7 @@ export interface ResourceDescriptor {
* *
* Note: if not provided and the resource kind is namespaced, then this defaults to `"default"` * Note: if not provided and the resource kind is namespaced, then this defaults to `"default"`
*/ */
namespace?: string | undefined; namespace?: string;
} }
export interface DeleteResourceDescriptor extends ResourceDescriptor { export interface DeleteResourceDescriptor extends ResourceDescriptor {
@ -559,7 +559,7 @@ export class KubeApi<
return null; return null;
} }
private ensureMetadataSelfLink<T extends { selfLink?: string | undefined; namespace?: string | undefined; name: string }>(metadata: T): asserts metadata is T & { selfLink: string } { private ensureMetadataSelfLink<T extends { selfLink?: string; namespace?: string; name: string }>(metadata: T): asserts metadata is T & { selfLink: string } {
metadata.selfLink ||= createKubeApiURL({ metadata.selfLink ||= createKubeApiURL({
apiPrefix: this.apiPrefix, apiPrefix: this.apiPrefix,
apiVersion: this.apiVersionWithGroup, apiVersion: this.apiVersionWithGroup,

View File

@ -26,13 +26,13 @@ export type OnLoadFailure = (error: unknown) => void;
export interface KubeObjectStoreLoadingParams { export interface KubeObjectStoreLoadingParams {
namespaces: string[]; namespaces: string[];
reqInit?: RequestInit | undefined; reqInit?: RequestInit;
/** /**
* A function that is called when listing fails. If set then blocks errors * A function that is called when listing fails. If set then blocks errors
* being rejected with * being rejected with
*/ */
onLoadFailure?: OnLoadFailure | undefined; onLoadFailure?: OnLoadFailure;
} }
export interface KubeObjectStoreLoadAllParams { export interface KubeObjectStoreLoadAllParams {
@ -44,7 +44,7 @@ export interface KubeObjectStoreLoadAllParams {
* A function that is called when listing fails. If set then blocks errors * A function that is called when listing fails. If set then blocks errors
* being rejected with * being rejected with
*/ */
onLoadFailure?: OnLoadFailure | undefined; onLoadFailure?: OnLoadFailure;
} }
export interface KubeObjectStoreSubscribeParams { export interface KubeObjectStoreSubscribeParams {
@ -52,7 +52,7 @@ export interface KubeObjectStoreSubscribeParams {
* A function that is called when listing fails. If set then blocks errors * A function that is called when listing fails. If set then blocks errors
* being rejected with * being rejected with
*/ */
onLoadFailure?: OnLoadFailure | undefined; onLoadFailure?: OnLoadFailure;
/** /**
* An optional parent abort controller * An optional parent abort controller

View File

@ -354,7 +354,7 @@ export interface Affinity {
} }
export interface LabelSelector { export interface LabelSelector {
matchLabels?: Record<string, string | undefined>; matchLabels?: Partial<Record<string, string>>;
matchExpressions?: LabelMatchExpression[]; matchExpressions?: LabelMatchExpression[];
} }
@ -465,7 +465,7 @@ export class KubeObject<
); );
} }
static stringifyLabels(labels?: Record<string, string | undefined>): string[] { static stringifyLabels(labels?: Partial<Record<string, string>>): string[] {
if (!labels) return []; if (!labels) return [];
return Object.entries(labels).map(([name, value]) => `${name}=${value}`); return Object.entries(labels).map(([name, value]) => `${name}=${value}`);

View File

@ -10,7 +10,7 @@ import searchUrlPageParamInjectable from "../input/search-url-page-param.injecta
import { KubeObject } from "../../../common/k8s-api/kube-object"; import { KubeObject } from "../../../common/k8s-api/kube-object";
import { Badge } from "../badge"; import { Badge } from "../badge";
export type GetLabelBadges = (entity: CatalogEntity, onClick?: ((evt: React.MouseEvent<any, MouseEvent>) => void) | undefined) => JSX.Element[]; export type GetLabelBadges = (entity: CatalogEntity, onClick?: (evt: React.MouseEvent<any, MouseEvent>) => void) => JSX.Element[];
const getLabelBadgesInjectable = getInjectable({ const getLabelBadgesInjectable = getInjectable({
id: "get-label-badges", id: "get-label-badges",

View File

@ -83,7 +83,7 @@ export const isUrl = inputValidator({
*/ */
export const isExtensionNameInstallRegex = TypedRegEx("^(?<name>(@[-\\w]+\\/)?[-\\w]+)(@(?<version>[a-z0-9-_.]+))?$", "gi") as { export const isExtensionNameInstallRegex = TypedRegEx("^(?<name>(@[-\\w]+\\/)?[-\\w]+)(@(?<version>[a-z0-9-_.]+))?$", "gi") as {
isMatch(val: string): boolean; isMatch(val: string): boolean;
captures(val: string): undefined | { name: string; version?: string | undefined }; captures(val: string): undefined | { name: string; version?: string };
}; };
export const isExtensionNameInstall = inputValidator({ export const isExtensionNameInstall = inputValidator({

View File

@ -72,7 +72,6 @@ interface Environment {
export const getApplicationBuilder = () => { export const getApplicationBuilder = () => {
const { rendererDi, mainDi, runSetups } = getDisForUnitTesting({ const { rendererDi, mainDi, runSetups } = getDisForUnitTesting({
doGeneralOverrides: true, doGeneralOverrides: true,
overrideCreateStorage: false,
}); });
const dis = { rendererDi, mainDi }; const dis = { rendererDi, mainDi };

View File

@ -2,9 +2,7 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { GetRendererDiForUnitTestingOptions } from "../renderer/getDiForUnitTesting";
import { getDiForUnitTesting as getRendererDi } from "../renderer/getDiForUnitTesting"; import { getDiForUnitTesting as getRendererDi } from "../renderer/getDiForUnitTesting";
import type { GetMainDiForUnitTestingOptions } from "../main/getDiForUnitTesting";
import { getDiForUnitTesting as getMainDi } from "../main/getDiForUnitTesting"; import { getDiForUnitTesting as getMainDi } from "../main/getDiForUnitTesting";
import { overrideIpcBridge } from "./override-ipc-bridge"; import { overrideIpcBridge } from "./override-ipc-bridge";
@ -12,7 +10,7 @@ export interface GetDiForUnitTestingOptions {
doGeneralOverrides?: boolean; doGeneralOverrides?: boolean;
} }
export const getDisForUnitTesting = (opts?: GetMainDiForUnitTestingOptions & GetRendererDiForUnitTestingOptions) => { export const getDisForUnitTesting = (opts?: GetDiForUnitTestingOptions) => {
const rendererDi = getRendererDi(opts); const rendererDi = getRendererDi(opts);
const mainDi = getMainDi(opts); const mainDi = getMainDi(opts);