fixes for TypeScript 5.0

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-03-25 15:30:22 +01:00
parent cc0e135cb9
commit 2898b6c8d5
22 changed files with 72 additions and 45 deletions
@@ -114,8 +114,9 @@ export function EntityAutocompletePicker<
} as Partial<T>);
}, [name, shouldAddFilter, selectedOptions, Filter, updateFilters]);
const filter = filters[name];
if (
(filters[name] && !('values' in filters[name])) ||
(filter && typeof filter === 'object' && !('values' in filter)) ||
!availableOptions.length
) {
return null;
@@ -57,11 +57,14 @@ export function FetchedEntityRefLinks<
error,
} = useAsync(async () => {
const refs = entityRefs.reduce((acc, current) => {
return 'metadata' in current ? acc : [...acc, parseEntityRef(current)];
if (typeof current === 'object' && 'metadata' in current) {
return acc;
}
return [...acc, parseEntityRef(current)];
}, new Array<CompoundEntityRef>());
const pureEntities = entityRefs.filter(
ref => 'metadata' in ref,
ref => typeof ref === 'object' && 'metadata' in ref,
) as Array<Entity>;
return refs.length > 0
@@ -161,8 +161,9 @@ export const EntityListProvider = <EntityFilters extends DefaultEntityFilters>(
const queryParams = Object.keys(requestedFilters).reduce(
(params, key) => {
const filter: EntityFilter | undefined =
requestedFilters[key as keyof EntityFilters];
const filter = requestedFilters[key as keyof EntityFilters] as
| EntityFilter
| undefined;
if (filter?.toQueryValue) {
params[key] = filter.toQueryValue();
}
@@ -70,10 +70,14 @@ function countTriggersPerDay(builds: ReadonlyArray<Build>) {
const values = Object.entries(days).map(([epoch, buildsThisDay]) => {
const datapoint = Object.fromEntries(
triggerReasons
.map(reason => [
reason,
buildsThisDay.filter(build => build.triggeredBy === reason).length,
])
.map(
reason =>
[
reason,
buildsThisDay.filter(build => build.triggeredBy === reason)
.length,
] as const,
)
.filter(([_type, count]) => count > 0),
) as Omit<TriggerReasonsDatapoint, '__epoch'>;
@@ -134,7 +134,7 @@ export const StarredRatingButtons = (props: StarredRatingButtonsProps) => {
return (
<>
{Object.values(FeedbackRatings)
.filter(o => typeof o === 'number')
.filter((o): o is number => typeof o === 'number')
.map(starRating => (
<IconButton
key={starRating}
@@ -73,7 +73,7 @@ export const IssuesList = ({
const filteredRepos = React.useMemo(
() =>
issuesByRepository && activeFilter.length
? activeFilter.reduce(
? activeFilter.reduce<IssuesByRepo>(
(acc, val) => ({
[val]: issuesByRepository[val],
...acc,
@@ -172,8 +172,9 @@ export const PlaylistListProvider = <
const queryParams = Object.keys(requestedFilters).reduce(
(params, key) => {
const filter: PlaylistFilter | undefined =
requestedFilters[key as keyof PlaylistFilters];
const filter = requestedFilters[key as keyof PlaylistFilters] as
| PlaylistFilter
| undefined;
if (filter?.toQueryValue) {
params[key] = filter.toQueryValue();
}
@@ -104,7 +104,7 @@ export class RollbarApi {
);
}
private async get<T>(url: string, accessToken?: string) {
private async get<T extends {}>(url: string, accessToken?: string) {
const fullUrl = buildUrl(url);
if (this.logger) {
@@ -119,7 +119,7 @@ export class RollbarApi {
.then(json => camelcaseKeys<T>(json?.result, { deep: true }));
}
private async getForProject<T>(
private async getForProject<T extends {}>(
url: string,
projectName: string,
useProjectToken = true,
@@ -120,7 +120,7 @@ describe('DefaultWorkflowRunner', () => {
foo: z.number(),
}),
},
}) as TemplateAction<unknown>,
}) as TemplateAction,
);
actionRegistry.register({
@@ -22,8 +22,8 @@ import { JsonObject } from '@backstage/types';
/** @public */
export type TemplateActionOptions<
TActionInput = {},
TActionOutput = {},
TActionInput extends JsonObject = {},
TActionOutput extends JsonObject = {},
TInputSchema extends Schema | z.ZodType = {},
TOutputSchema extends Schema | z.ZodType = {},
> = {
@@ -48,10 +48,18 @@ export const createTemplateAction = <
TOutputParams extends JsonObject = JsonObject,
TInputSchema extends Schema | z.ZodType = {},
TOutputSchema extends Schema | z.ZodType = {},
TActionInput = TInputSchema extends z.ZodType<any, any, infer IReturn>
TActionInput extends JsonObject = TInputSchema extends z.ZodType<
any,
any,
infer IReturn
>
? IReturn
: TInputParams,
TActionOutput = TOutputSchema extends z.ZodType<any, any, infer IReturn>
TActionOutput extends JsonObject = TOutputSchema extends z.ZodType<
any,
any,
infer IReturn
>
? IReturn
: TOutputParams,
>(
+2 -2
View File
@@ -75,8 +75,8 @@ export type ActionContext<
/** @public */
export type TemplateAction<
TActionInput = unknown,
TActionOutput = JsonObject,
TActionInput extends JsonObject = JsonObject,
TActionOutput extends JsonObject = JsonObject,
> = {
id: string;
description?: string;
@@ -64,7 +64,7 @@ export type FieldExtensionOptions<
*/
export interface FieldExtensionComponentProps<
TFieldReturnValue,
TUiOptions extends {} = {},
TUiOptions = unknown,
> extends FieldProps<TFieldReturnValue> {
uiSchema: FieldProps['uiSchema'] & {
'ui:options'?: TUiOptions;
+1 -4
View File
@@ -66,9 +66,6 @@ createDevApp()
<EntityGridItem xs={12} md={6} entity={entity('passed')}>
<EntitySonarQubeCard />
</EntityGridItem>
<EntityGridItem xs={12} entity={entity(undefined)}>
<EntitySonarQubeCard />
</EntityGridItem>
</Grid>
</Content>
</Page>
@@ -79,7 +76,7 @@ createDevApp()
deps: {},
factory: () =>
({
getFindingSummary: async componentKey => {
getFindingSummary: async ({ componentKey }) => {
switch (componentKey) {
case 'error':
throw new Error('Error!');
@@ -59,7 +59,7 @@ export const Content = (props: StackOverflowQuestionsContentProps) => {
return <Typography paragraph>could not load questions</Typography>;
}
const getSecondaryText = (answer_count: Number) =>
const getSecondaryText = (answer_count: number) =>
answer_count > 1 ? `${answer_count} answers` : `${answer_count} answer`;
return (