Skip to content

Commit

Permalink
fix(app-page-builder): improve types for TS 4.9.5
Browse files Browse the repository at this point in the history
Pavel910 committed Sep 14, 2024
1 parent 9e5a1d1 commit 48f6af7
Showing 6 changed files with 16 additions and 18 deletions.
4 changes: 1 addition & 3 deletions packages/app-page-builder-elements/src/createRenderer.tsx
Original file line number Diff line number Diff line change
@@ -148,10 +148,8 @@ export function createRenderer<
{ ...attributes, class: o },
<>
{BeforeRenderer ? <BeforeRenderer /> : null}

{/* Would've liked if the `as unknown as T` part wasn't
needed, but unfortunately, could not figure it out. */}
<DecoratableRendererComponent
key={"decoratable-component"}
{...(componentProps as unknown as TRenderComponentProps)}
/>
{AfterRenderer ? <AfterRenderer /> : null}
8 changes: 0 additions & 8 deletions packages/app-page-builder-elements/src/inputs/ElementInput.ts
Original file line number Diff line number Diff line change
@@ -50,21 +50,13 @@ export class ElementInput<TValue = unknown, TElementData = any> {
}

getDefaultValue(element: Element<TElementData>): TValue | undefined {
if (!this.params.getDefaultValue) {
return this.getValueFromDefaultLocation(element);
}

const value = this.params.getDefaultValue({ element });
if (!value) {
return undefined;
}

return value as TValue;
}

private getValueFromDefaultLocation(element: Element) {
return element.data.inputs[this.params.name];
}
}

export type ElementInputValues<T extends ElementInputs> = {
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ import { TranslatedCollection } from "~/translations/translatedCollection/Transl
import { Loading } from "~/translations/Loading";
import { ListCache } from "~/translations/ListCache";
import { IGetTranslatedCollectionGateway } from "~/translations/translatedCollection/getTranslatedCollection/IGetTranslatedCollectionGateway";
import { GenericRecord } from "@webiny/app/types";

export class GetTranslatedCollectionRepository implements IGetTranslatedCollectionRepository {
private readonly loading: Loading;
@@ -68,7 +69,7 @@ export class GetTranslatedCollectionRepository implements IGetTranslatedCollecti
return this.loading;
}

getTranslatedCollection<TContext>(
getTranslatedCollection<TContext extends GenericRecord<string> = GenericRecord<string>>(
collectionId: string,
languageCode: string
): TranslatedCollection<TContext> | undefined {
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Loading } from "~/translations/Loading";
import { TranslatedCollection } from "~/translations/translatedCollection/TranslatedCollection";
import { GenericRecord } from "@webiny/app/types";

export interface IGetTranslatedCollectionRepository {
execute(collectionId: string, languageCode: string): Promise<TranslatedCollection | undefined>;
getLoading(): Loading;
getTranslatedCollection<TContext>(
getTranslatedCollection<TContext extends GenericRecord<string> = GenericRecord<string>>(
collectionId: string,
languageCode: string
): TranslatedCollection<TContext> | undefined;
Original file line number Diff line number Diff line change
@@ -9,7 +9,9 @@ import { GetTranslatedCollectionRepository } from "~/translations/translatedColl
import { translatedCollectionCache } from "~/translations/translatedCollection/translatedCollectionCache";
import { GenericRecord } from "@webiny/app/types";

export const useTranslatedCollection = <TContext = GenericRecord<string>>(
export const useTranslatedCollection = <
TContext extends GenericRecord<string> = GenericRecord<string>
>(
collectionId: string,
languageCode: string
) => {
12 changes: 8 additions & 4 deletions packages/react-composition/src/makeDecoratable.tsx
Original file line number Diff line number Diff line change
@@ -36,12 +36,16 @@ function makeDecoratableComponent<T extends GenericComponent>(
);
};

Decoratable.original = Component;
Decoratable.originalName = name;
Decoratable.displayName = `Decoratable<${name}>`;
const staticProps = {
original: Component,
originalName: name,
displayName: `Decoratable<${name}>`
};

return withDecoratorFactory()(
Decoratable as DecoratableComponent<typeof Component & typeof Decoratable>
Object.assign(Decoratable, staticProps) as DecoratableComponent<
typeof Component & typeof staticProps
>
);
}

0 comments on commit 48f6af7

Please sign in to comment.