Skip to content

Commit

Permalink
Create GenericObject to satisfy TypeScript
Browse files Browse the repository at this point in the history
Previously in `ent-search`, we had a generic `IObject` interface that we could use on keyed objects. It was not migrated over since it uses `any` and Kibana has a generic `object` type we can use in most situations. However, when we are checking for keys in our code, `object` does not work. This commit is an attempt at making a generic interface we can use.
  • Loading branch information
scottybollinger committed Nov 17, 2020
1 parent d9b78db commit 7832179
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,9 @@ export interface CustomSource {
name: string;
id: string;
}

export type AnyType = string | number | boolean | object | undefined | null;

export interface GenericObject {
[key: string]: AnyType | AnyType[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { DEFAULT_META } from '../../../shared/constants';
import { AppLogic } from '../../app_logic';
import { NOT_FOUND_PATH } from '../../routes';
import { ContentSourceFullData, CustomSource, Meta } from '../../types';
import { ContentSourceFullData, CustomSource, Meta, GenericObject } from '../../types';

export interface SourceActions {
onInitializeSource(contentSource: ContentSourceFullData): ContentSourceFullData;
Expand Down Expand Up @@ -118,8 +118,7 @@ interface SourceValues {
newCustomSource: CustomSource;
currentServiceType: string;
githubOrganizations: string[];
selectedGithubOrganizationsMap: object;
selectedGithubOrganizations: object;
selectedGithubOrganizationsMap: GenericObject;
selectedGithubOrganizations: string[];
}

Expand Down Expand Up @@ -345,13 +344,13 @@ export const SourceLogic = kea<MakeLogicType<SourceValues, SourceActions>>({
},
],
selectedGithubOrganizationsMap: [
{},
{} as GenericObject,
{
setSelectedGithubOrganizations: (state, option) => ({
setSelectedGithubOrganizations: (state: GenericObject, option) => ({
...state,
...{ [option]: !state[option] },
}),
resetSourceState: () => [],
resetSourceState: () => ({}),
},
],
},
Expand Down Expand Up @@ -562,7 +561,7 @@ export const SourceLogic = kea<MakeLogicType<SourceValues, SourceActions>>({
password: passwordValue || undefined,
organizations: githubOrganizations.length > 0 ? githubOrganizations : undefined,
indexPermissions: indexPermissionsValue || undefined,
};
} as GenericObject;

// Remove undefined values from params
Object.keys(params).forEach((key) => params[key] === undefined && delete params[key]);
Expand Down

0 comments on commit 7832179

Please sign in to comment.