Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit c1d4199

Browse files
authored
Upgrade target to es2022 (#12852)
* Upgrade target to es2021 Signed-off-by: Michael Telatynski <[email protected]> * Upgrade to es2022 Signed-off-by: Michael Telatynski <[email protected]> * Fix babel config Signed-off-by: Michael Telatynski <[email protected]> * Fix React contexts Signed-off-by: Michael Telatynski <[email protected]> * Fix types Signed-off-by: Michael Telatynski <[email protected]> * Fix React state Signed-off-by: Michael Telatynski <[email protected]> * Iterate Signed-off-by: Michael Telatynski <[email protected]> --------- Signed-off-by: Michael Telatynski <[email protected]>
1 parent 9cd0c24 commit c1d4199

Some content is hidden

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

68 files changed

+86
-148
lines changed

babel.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ module.exports = {
1010
"last 2 Safari versions",
1111
"last 2 Edge versions",
1212
],
13+
include: ["@babel/plugin-transform-class-properties"],
1314
},
1415
],
15-
"@babel/preset-typescript",
16+
["@babel/preset-typescript", { allowDeclareFields: true }],
1617
"@babel/preset-react",
1718
],
1819
plugins: [
1920
"@babel/plugin-proposal-export-default-from",
2021
"@babel/plugin-transform-numeric-separator",
21-
"@babel/plugin-transform-class-properties",
2222
"@babel/plugin-transform-object-rest-spread",
2323
"@babel/plugin-syntax-dynamic-import",
2424
"@babel/plugin-transform-runtime",

playwright/plugins/homeserver/dendrite/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ const dendriteConfigFile = "dendrite.yaml";
2929

3030
// Surprisingly, Dendrite implements the same register user Admin API Synapse, so we can just extend it
3131
export class Dendrite extends Synapse implements Homeserver, HomeserverInstance {
32-
public config: HomeserverConfig & { serverId: string };
3332
protected image = "matrixdotorg/dendrite-monolith:main";
3433
protected entrypoint = "/usr/bin/dendrite";
3534

playwright/tsconfig.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"compilerOptions": {
3-
"target": "es2018",
3+
"target": "es2022",
44
"jsx": "react",
5-
"lib": ["ESNext", "es2021", "dom", "dom.iterable"],
5+
"lib": ["ESNext", "es2022", "dom", "dom.iterable"],
66
"resolveJsonModule": true,
77
"esModuleInterop": true,
88
"moduleResolution": "node",

src/@types/global.d.ts

+1-56
Original file line numberDiff line numberDiff line change
@@ -144,69 +144,14 @@ declare global {
144144
usageDetails?: { [key: string]: number };
145145
}
146146

147-
// https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas
148-
interface OffscreenCanvas {
149-
convertToBlob(opts?: { type?: string; quality?: number }): Promise<Blob>;
150-
}
151-
152-
interface HTMLAudioElement {
153-
type?: string;
154-
}
155-
156-
interface HTMLVideoElement {
157-
type?: string;
158-
}
159-
160-
// Add Chrome-specific `instant` ScrollBehaviour
161-
type _ScrollBehavior = ScrollBehavior | "instant";
162-
163-
interface _ScrollOptions {
164-
behavior?: _ScrollBehavior;
165-
}
166-
167-
interface _ScrollIntoViewOptions extends _ScrollOptions {
168-
block?: ScrollLogicalPosition;
169-
inline?: ScrollLogicalPosition;
170-
}
171-
172147
interface Element {
173148
// Safari & IE11 only have this prefixed: we used prefixed versions
174149
// previously so let's continue to support them for now
175150
webkitRequestFullScreen(options?: FullscreenOptions): Promise<void>;
176151
msRequestFullscreen(options?: FullscreenOptions): Promise<void>;
177-
scrollIntoView(arg?: boolean | _ScrollIntoViewOptions): void;
178-
}
179-
180-
interface Error {
181-
// Standard
182-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
183-
cause?: unknown;
184-
185-
// Non-standard
186-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/fileName
187-
fileName?: string;
188-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/lineNumber
189-
lineNumber?: number;
190-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/columnNumber
191-
columnNumber?: number;
192-
}
193-
194-
// We can remove these pieces if we ever update to `target: "es2022"` in our
195-
// TypeScript config which supports the new `cause` property, see
196-
// https://github.com/vector-im/element-web/issues/24913
197-
interface ErrorOptions {
198-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause
199-
cause?: unknown;
200-
}
201-
202-
interface ErrorConstructor {
203-
new (message?: string, options?: ErrorOptions): Error;
204-
(message?: string, options?: ErrorOptions): Error;
152+
// scrollIntoView(arg?: boolean | _ScrollIntoViewOptions): void;
205153
}
206154

207-
// eslint-disable-next-line no-var
208-
var Error: ErrorConstructor;
209-
210155
// https://github.com/microsoft/TypeScript/issues/28308#issuecomment-650802278
211156
interface AudioWorkletProcessor {
212157
readonly port: MessagePort;

src/components/structures/EmbeddedPage.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ interface IState {
4545

4646
export default class EmbeddedPage extends React.PureComponent<IProps, IState> {
4747
public static contextType = MatrixClientContext;
48-
public context!: React.ContextType<typeof MatrixClientContext>;
48+
public declare context: React.ContextType<typeof MatrixClientContext>;
4949
private unmounted = false;
5050
private dispatcherRef: string | null = null;
5151

src/components/structures/FilePanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ interface IState {
5959
*/
6060
class FilePanel extends React.Component<IProps, IState> {
6161
public static contextType = RoomContext;
62-
public context!: React.ContextType<typeof RoomContext>;
62+
public declare context: React.ContextType<typeof RoomContext>;
6363

6464
// This is used to track if a decrypted event was a live event and should be
6565
// added to the timeline.

src/components/structures/MessagePanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ interface IReadReceiptForUser {
205205
*/
206206
export default class MessagePanel extends React.Component<IProps, IState> {
207207
public static contextType = RoomContext;
208-
public context!: React.ContextType<typeof RoomContext>;
208+
public declare context: React.ContextType<typeof RoomContext>;
209209

210210
public static defaultProps = {
211211
disableGrouping: false,

src/components/structures/NotificationPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ interface IState {
4242
*/
4343
export default class NotificationPanel extends React.PureComponent<IProps, IState> {
4444
public static contextType = RoomContext;
45-
public context!: React.ContextType<typeof RoomContext>;
45+
public declare context: React.ContextType<typeof RoomContext>;
4646

4747
private card = React.createRef<HTMLDivElement>();
4848

src/components/structures/RightPanel.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ interface IState {
7373

7474
export default class RightPanel extends React.Component<Props, IState> {
7575
public static contextType = MatrixClientContext;
76-
public context!: React.ContextType<typeof MatrixClientContext>;
76+
public declare context: React.ContextType<typeof MatrixClientContext>;
7777

7878
public constructor(props: Props, context: React.ContextType<typeof MatrixClientContext>) {
7979
super(props, context);

src/components/structures/RoomStatusBar.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,10 @@ interface IState {
9797
export default class RoomStatusBar extends React.PureComponent<IProps, IState> {
9898
private unmounted = false;
9999
public static contextType = MatrixClientContext;
100-
public context!: React.ContextType<typeof MatrixClientContext>;
100+
public declare context: React.ContextType<typeof MatrixClientContext>;
101101

102102
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
103103
super(props, context);
104-
this.context = context; // XXX: workaround for lack of `declare` support on `public context!:` definition
105104

106105
this.state = {
107106
syncState: this.context.getSyncState(),

src/components/structures/RoomView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
417417
private roomViewBody = createRef<HTMLDivElement>();
418418

419419
public static contextType = SDKContext;
420-
public context!: React.ContextType<typeof SDKContext>;
420+
public declare context: React.ContextType<typeof SDKContext>;
421421

422422
public constructor(props: IRoomProps, context: React.ContextType<typeof SDKContext>) {
423423
super(props, context);

src/components/structures/SpaceRoomView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ const SpaceSetupPrivateInvite: React.FC<{
605605

606606
export default class SpaceRoomView extends React.PureComponent<IProps, IState> {
607607
public static contextType = MatrixClientContext;
608-
public context!: React.ContextType<typeof MatrixClientContext>;
608+
public declare context: React.ContextType<typeof MatrixClientContext>;
609609

610610
private readonly dispatcherRef: string;
611611

src/components/structures/ThreadView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ interface IState {
8383

8484
export default class ThreadView extends React.Component<IProps, IState> {
8585
public static contextType = RoomContext;
86-
public context!: React.ContextType<typeof RoomContext>;
86+
public declare context: React.ContextType<typeof RoomContext>;
8787

8888
private dispatcherRef: string | null = null;
8989
private readonly layoutWatcherRef: string;

src/components/structures/TimelinePanel.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ interface IEventIndexOpts {
241241
*/
242242
class TimelinePanel extends React.Component<IProps, IState> {
243243
public static contextType = RoomContext;
244-
public context!: React.ContextType<typeof RoomContext>;
244+
public declare context: React.ContextType<typeof RoomContext>;
245245

246246
// a map from room id to read marker event timestamp
247247
public static roomReadMarkerTsMap: Record<string, number> = {};
@@ -273,7 +273,6 @@ class TimelinePanel extends React.Component<IProps, IState> {
273273

274274
public constructor(props: IProps, context: React.ContextType<typeof RoomContext>) {
275275
super(props, context);
276-
this.context = context;
277276

278277
debuglog("mounting");
279278

src/components/structures/UserMenu.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const below = (rect: PartialDOMRect): MenuProps => {
9090

9191
export default class UserMenu extends React.Component<IProps, IState> {
9292
public static contextType = SDKContext;
93-
public context!: React.ContextType<typeof SDKContext>;
93+
public declare context: React.ContextType<typeof SDKContext>;
9494

9595
private dispatcherRef?: string;
9696
private themeWatcherRef?: string;
@@ -100,7 +100,6 @@ export default class UserMenu extends React.Component<IProps, IState> {
100100
public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
101101
super(props, context);
102102

103-
this.context = context;
104103
this.state = {
105104
contextMenuPosition: null,
106105
isDarkTheme: this.isUserOnDarkTheme(),

src/components/structures/UserView.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface IState {
4141

4242
export default class UserView extends React.Component<IProps, IState> {
4343
public static contextType = MatrixClientContext;
44-
public context!: React.ContextType<typeof MatrixClientContext>;
44+
public declare context: React.ContextType<typeof MatrixClientContext>;
4545

4646
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
4747
super(props, context);

src/components/structures/auth/SoftLogout.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,11 @@ interface IState {
7272

7373
export default class SoftLogout extends React.Component<IProps, IState> {
7474
public static contextType = SDKContext;
75-
public context!: React.ContextType<typeof SDKContext>;
75+
public declare context: React.ContextType<typeof SDKContext>;
7676

7777
public constructor(props: IProps, context: React.ContextType<typeof SDKContext>) {
7878
super(props, context);
7979

80-
this.context = context;
81-
8280
this.state = {
8381
loginView: LoginView.Loading,
8482
busy: false,

src/components/views/context_menus/MessageContextMenu.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ interface IState {
133133

134134
export default class MessageContextMenu extends React.Component<IProps, IState> {
135135
public static contextType = RoomContext;
136-
public context!: React.ContextType<typeof RoomContext>;
136+
public declare context: React.ContextType<typeof RoomContext>;
137137

138138
private reactButtonRef = createRef<any>(); // XXX Ref to a functional component
139139

src/components/views/elements/AppTile.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ interface IState {
120120

121121
export default class AppTile extends React.Component<IProps, IState> {
122122
public static contextType = MatrixClientContext;
123-
public context!: ContextType<typeof MatrixClientContext>;
123+
public declare context: ContextType<typeof MatrixClientContext>;
124124

125125
public static defaultProps: Partial<IProps> = {
126126
waitForIframeLoad: true,
@@ -144,7 +144,6 @@ export default class AppTile extends React.Component<IProps, IState> {
144144

145145
public constructor(props: IProps, context: ContextType<typeof MatrixClientContext>) {
146146
super(props, context);
147-
this.context = context; // XXX: workaround for lack of `declare` support on `public context!:` definition
148147

149148
// Tiles in miniMode are floating, and therefore not docked
150149
if (!this.props.miniMode) {

src/components/views/elements/EventListSummary.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export default class EventListSummary extends React.Component<
8181
IProps & Required<Pick<IProps, "summaryLength" | "threshold" | "avatarsMaxLength" | "layout">>
8282
> {
8383
public static contextType = RoomContext;
84-
public context!: React.ContextType<typeof RoomContext>;
84+
public declare context: React.ContextType<typeof RoomContext>;
8585

8686
public static defaultProps = {
8787
summaryLength: 1,

src/components/views/elements/PersistentApp.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ interface IProps {
3232

3333
export default class PersistentApp extends React.Component<IProps> {
3434
public static contextType = MatrixClientContext;
35-
public context!: ContextType<typeof MatrixClientContext>;
35+
public declare context: ContextType<typeof MatrixClientContext>;
3636
private room: Room;
3737

3838
public constructor(props: IProps, context: ContextType<typeof MatrixClientContext>) {

src/components/views/elements/ReplyChain.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ interface IState {
7373
// be low as each event being loaded (after the first) is triggered by an explicit user action.
7474
export default class ReplyChain extends React.Component<IProps, IState> {
7575
public static contextType = RoomContext;
76-
public context!: React.ContextType<typeof RoomContext>;
76+
public declare context: React.ContextType<typeof RoomContext>;
7777

7878
private unmounted = false;
7979
private room: Room;

src/components/views/elements/RoomAliasField.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface IState {
4141
// Controlled form component wrapping Field for inputting a room alias scoped to a given domain
4242
export default class RoomAliasField extends React.PureComponent<IProps, IState> {
4343
public static contextType = MatrixClientContext;
44-
public context!: React.ContextType<typeof MatrixClientContext>;
44+
public declare context: React.ContextType<typeof MatrixClientContext>;
4545

4646
private fieldRef = createRef<Field>();
4747

src/components/views/emojipicker/ReactionPicker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ interface IState {
3737

3838
class ReactionPicker extends React.Component<IProps, IState> {
3939
public static contextType = RoomContext;
40-
public context!: React.ContextType<typeof RoomContext>;
40+
public declare context: React.ContextType<typeof RoomContext>;
4141

4242
public constructor(props: IProps, context: React.ContextType<typeof RoomContext>) {
4343
super(props, context);

src/components/views/emojipicker/Search.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface IProps {
3131

3232
class Search extends React.PureComponent<IProps> {
3333
public static contextType = RovingTabIndexContext;
34-
public context!: React.ContextType<typeof RovingTabIndexContext>;
34+
public declare context: React.ContextType<typeof RovingTabIndexContext>;
3535

3636
private inputRef = React.createRef<HTMLInputElement>();
3737

src/components/views/location/LocationPicker.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const isSharingOwnLocation = (shareType: LocationShareType): boolean =>
5050

5151
class LocationPicker extends React.Component<ILocationPickerProps, IState> {
5252
public static contextType = MatrixClientContext;
53-
public context!: React.ContextType<typeof MatrixClientContext>;
53+
public declare context: React.ContextType<typeof MatrixClientContext>;
5454
private map?: maplibregl.Map;
5555
private geolocate?: maplibregl.GeolocateControl;
5656
private marker?: maplibregl.Marker;

src/components/views/messages/EditHistoryMessage.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ interface IState {
5252

5353
export default class EditHistoryMessage extends React.PureComponent<IProps, IState> {
5454
public static contextType = MatrixClientContext;
55-
public context!: React.ContextType<typeof MatrixClientContext>;
55+
public declare context: React.ContextType<typeof MatrixClientContext>;
5656

5757
private content = createRef<HTMLDivElement>();
5858
private pills: Element[] = [];
5959
private tooltips: Element[] = [];
6060

6161
public constructor(props: IProps, context: React.ContextType<typeof MatrixClientContext>) {
6262
super(props, context);
63-
this.context = context;
6463

6564
const cli = this.context;
6665
const userId = cli.getSafeUserId();

src/components/views/messages/MAudioBody.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface IState {
3838

3939
export default class MAudioBody extends React.PureComponent<IBodyProps, IState> {
4040
public static contextType = RoomContext;
41-
public context!: React.ContextType<typeof RoomContext>;
41+
public declare context: React.ContextType<typeof RoomContext>;
4242

4343
public state: IState = {};
4444

src/components/views/messages/MFileBody.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ interface IState {
106106

107107
export default class MFileBody extends React.Component<IProps, IState> {
108108
public static contextType = RoomContext;
109-
public context!: React.ContextType<typeof RoomContext>;
109+
public declare context: React.ContextType<typeof RoomContext>;
110110

111111
public state: IState = {};
112112

src/components/views/messages/MImageBody.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ interface IState {
6565

6666
export default class MImageBody extends React.Component<IBodyProps, IState> {
6767
public static contextType = RoomContext;
68-
public context!: React.ContextType<typeof RoomContext>;
68+
public declare context: React.ContextType<typeof RoomContext>;
6969

7070
private unmounted = true;
7171
private image = createRef<HTMLImageElement>();

src/components/views/messages/MLocationBody.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ interface IState {
3838

3939
export default class MLocationBody extends React.Component<IBodyProps, IState> {
4040
public static contextType = MatrixClientContext;
41-
public context!: React.ContextType<typeof MatrixClientContext>;
41+
public declare context: React.ContextType<typeof MatrixClientContext>;
4242

4343
private unmounted = false;
4444
private mapId: string;

0 commit comments

Comments
 (0)