Skip to content

Commit 1e42f28

Browse files
authored
Harden Settings using mapped types (#28775)
* Harden Settings using mapped types Signed-off-by: Michael Telatynski <[email protected]> * Fix issues found during hardening Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> * Remove oidc native flow stale key Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 4e1bd69 commit 1e42f28

File tree

90 files changed

+576
-274
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+576
-274
lines changed

scripts/analyse_unused_exports.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ ignore.push("/OpenSpotlightPayload.ts");
1919
ignore.push("/PinnedMessageBadge.tsx");
2020
ignore.push("/editor/mock.ts");
2121
ignore.push("DeviceIsolationModeController.ts");
22+
ignore.push("/json.ts");
23+
ignore.push("/ReleaseAnnouncementStore.ts");
24+
ignore.push("/WidgetLayoutStore.ts");
25+
ignore.push("/common.ts");
2226

2327
// We ignore js-sdk by default as it may export for other non element-web projects
2428
if (!includeJSSDK) ignore.push("matrix-js-sdk");

src/@types/common.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,11 @@ type DeepReadonlyObject<T> = {
4444
};
4545

4646
export type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> & U[keyof U];
47+
48+
/**
49+
* Returns a union type of the keys of the input Object type whose values are assignable to the given Item type.
50+
* Based on https://stackoverflow.com/a/57862073
51+
*/
52+
export type Assignable<Object, Item> = {
53+
[Key in keyof Object]: Object[Key] extends Item ? Key : never;
54+
}[keyof Object];

src/@types/json.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Copyright 2024 New Vector Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only
5+
Please see LICENSE files in the repository root for full details.
6+
*/
7+
8+
export type JsonValue = null | string | number | boolean;
9+
export type JsonArray = Array<JsonValue | JsonObject | JsonArray>;
10+
export interface JsonObject {
11+
[key: string]: JsonObject | JsonArray | JsonValue;
12+
}
13+
export type Json = JsonArray | JsonObject;

src/Notifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class NotifierClass extends TypedEventEmitter<keyof EmittedEvents, EmittedEvents
176176
url: string;
177177
name: string;
178178
type: string;
179-
size: string;
179+
size: number;
180180
} | null {
181181
// We do no caching here because the SDK caches setting
182182
// and the browser will cache the sound.

src/components/structures/LoggedInView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ class LoggedInView extends React.Component<IProps, IState> {
246246
} else {
247247
backgroundImage = OwnProfileStore.instance.getHttpAvatarUrl();
248248
}
249-
this.setState({ backgroundImage });
249+
this.setState({ backgroundImage: backgroundImage ?? undefined });
250250
};
251251

252252
public canResetTimelineInRoom = (roomId: string): boolean => {

src/components/views/beta/BetaCard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import SettingsFlag from "../elements/SettingsFlag";
2020
import { useFeatureEnabled } from "../../../hooks/useSettings";
2121
import InlineSpinner from "../elements/InlineSpinner";
2222
import { shouldShowFeedback } from "../../../utils/Feedback";
23+
import { FeatureSettingKey } from "../../../settings/Settings.tsx";
2324

2425
// XXX: Keep this around for re-use in future Betas
2526

2627
interface IProps {
2728
title?: string;
28-
featureId: string;
29+
featureId: FeatureSettingKey;
2930
}
3031

3132
interface IBetaPillProps {

src/components/views/context_menus/RoomGeneralContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export const RoomGeneralContextMenu: React.FC<RoomGeneralContextMenuProps> = ({
282282
}
283283
})();
284284

285-
const developerModeEnabled = useSettingValue<boolean>("developerMode");
285+
const developerModeEnabled = useSettingValue("developerMode");
286286
const developerToolsOption = developerModeEnabled ? (
287287
<DeveloperToolsOption onFinished={onFinished} roomId={room.roomId} />
288288
) : null;

src/components/views/context_menus/WidgetContextMenu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ const showDeleteButton = (canModify: boolean, onDeleteClick: undefined | (() =>
7171

7272
const showSnapshotButton = (widgetMessaging: ClientWidgetApi | undefined): boolean => {
7373
return (
74-
SettingsStore.getValue<boolean>("enableWidgetScreenshots") &&
74+
SettingsStore.getValue("enableWidgetScreenshots") &&
7575
!!widgetMessaging?.hasCapability(MatrixCapabilities.Screenshots)
7676
);
7777
};

src/components/views/dialogs/AddExistingToSpaceDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const AddExistingToSpace: React.FC<IAddExistingToSpaceProps> = ({
131131
onFinished,
132132
}) => {
133133
const cli = useContext(MatrixClientContext);
134-
const msc3946ProcessDynamicPredecessor = useSettingValue<boolean>("feature_dynamic_room_predecessors");
134+
const msc3946ProcessDynamicPredecessor = useSettingValue("feature_dynamic_room_predecessors");
135135
const visibleRooms = useMemo(
136136
() =>
137137
cli

src/components/views/dialogs/BetaFeedbackDialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ import defaultDispatcher from "../../../dispatcher/dispatcher";
1515
import { Action } from "../../../dispatcher/actions";
1616
import { UserTab } from "./UserTab";
1717
import GenericFeatureFeedbackDialog from "./GenericFeatureFeedbackDialog";
18+
import { SettingKey } from "../../../settings/Settings.tsx";
1819

1920
// XXX: Keep this around for re-use in future Betas
2021

2122
interface IProps {
22-
featureId: string;
23+
featureId: SettingKey;
2324
onFinished(sendFeedback?: boolean): void;
2425
}
2526

@@ -35,7 +36,7 @@ const BetaFeedbackDialog: React.FC<IProps> = ({ featureId, onFinished }) => {
3536
rageshakeLabel={info.feedbackLabel}
3637
rageshakeData={Object.fromEntries(
3738
(SettingsStore.getBetaInfo(featureId)?.extraSettings || []).map((k) => {
38-
return SettingsStore.getValue(k);
39+
return [k, SettingsStore.getValue(k)];
3940
}),
4041
)}
4142
>

0 commit comments

Comments
 (0)