Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade ts v5.1 #20

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,8 @@ export const UserProfilesSelectable = <Option extends UserProfileWithAvatar | nu
return (
<EuiSelectable
data-test-subj={props['data-test-subj']}
// @ts-expect-error upgrade typescript v5.1.6
options={displayedOptions}
onChange={(
nextOptions: Array<EuiSelectableOption<{ data: Partial<UserProfileWithAvatar> }>>
) => {
onChange={(nextOptions: SelectableOption[]) => {
if (!onChange) {
return;
}
Expand Down Expand Up @@ -330,34 +327,27 @@ export const UserProfilesSelectable = <Option extends UserProfileWithAvatar | nu
noMatchesMessage={noMatchesMessage}
emptyMessage={emptyMessage}
errorMessage={errorMessage}
renderOption={(option, searchValue) => {
// @ts-expect-error upgrade typescript v5.1.6
renderOption={(option: SelectableOption, searchValue) => {
if (option.user) {
// @ts-expect-error upgrade typescript v5.1.6
const displayName = getUserDisplayName(option.user);
return (
<>
<div className="eui-textTruncate">
<EuiHighlight search={searchValue}>{displayName}</EuiHighlight>
</div>
{
/* @ts-expect-error upgrade typescript v5.1.6 */
option.user.email && option.user.email !== displayName ? (
<EuiText
size={'xs'}
color={option.disabled ? 'disabled' : 'subdued'}
className="eui-textTruncate"
>
{searchValue ? (
/* @ts-expect-error upgrade typescript v5.1.6 */
<EuiHighlight search={searchValue}>{option.user.email}</EuiHighlight>
) : (
/* @ts-expect-error upgrade typescript v5.1.6 */
option.user.email
)}
</EuiText>
) : undefined
}
{option.user.email && option.user.email !== displayName ? (
<EuiText
size={'xs'}
color={option.disabled ? 'disabled' : 'subdued'}
className="eui-textTruncate"
>
{searchValue ? (
<EuiHighlight search={searchValue}>{option.user.email}</EuiHighlight>
) : (
option.user.email
)}
</EuiText>
) : undefined}
</>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function isAPIKeyCredentials(
| ElasticsearchAnonymousUserCredentials
| APIKeyCredentials
| UsernameAndPasswordCredentials
): credentials is APIKeyCredentials {
): credentials is Readonly<APIKeyCredentials> {
return !!(credentials as APIKeyCredentials).apiKey;
}

Expand Down Expand Up @@ -105,9 +105,7 @@ export class AnonymousAuthenticationProvider extends BaseAuthenticationProvider
return new HTTPAuthorizationHeader(
'Basic',
new BasicHTTPAuthorizationHeaderCredentials(
// @ts-expect-error upgrade typescript v5.1.6
credentials.username,
// @ts-expect-error upgrade typescript v5.1.6
credentials.password
).toString()
);
Expand Down
23 changes: 10 additions & 13 deletions x-pack/plugins/security/server/lib/flatten_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@

import { compact, isObject } from 'lodash';

// Inspired by x-pack/plugins/observability_solution/apm/public/utils/flatten_object.ts
// Slighly modified to have key/value exposed as Object.
// Slightly modified to have key/value exposed as Object.
export const flattenObject = (
kc13greiner marked this conversation as resolved.
Show resolved Hide resolved
item: Record<any, any | any[]> | null | undefined,
accDefault: Record<string, any> = {},
item: Record<PropertyKey, unknown> | null | undefined,
accDefault: Record<PropertyKey, unknown> = {},
parentKey?: string
): Record<string, any> => {
): Record<PropertyKey, unknown> => {
if (item) {
const isArrayWithSingleValue = Array.isArray(item) && item.length === 1;
return Object.keys(item)
.sort()
.reduce<Record<string, any>>((acc, key) => {
.reduce<Record<PropertyKey, unknown>>((acc, key) => {
const childKey = isArrayWithSingleValue ? '' : key;
const currentKey = compact([parentKey, childKey]).join('.');
// item[key] can be a primitive (string, number, boolean, null, undefined) or Object or Array
// @ts-expect-error upgrade typescript v5.1.6
if (isObject(item[key])) {
// @ts-expect-error upgrade typescript v5.1.6
flattenObject(item[key], acc, currentKey);

const value = item[key];
if (isObject(value)) {
flattenObject(value as Record<PropertyKey, unknown>, acc, currentKey);
} else {
// @ts-expect-error upgrade typescript v5.1.6
acc[currentKey] = item[key];
acc[currentKey] = value;
}

return acc;
Expand Down
Loading