Skip to content

Commit 1bc1055

Browse files
committed
build(deps): upgrade to TypeScript 5.1
1 parent c07f3c8 commit 1bc1055

21 files changed

+87
-60
lines changed

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"semver": "^7.3.4",
6767
"shell-env": "^3.0.1",
6868
"tmp": "0.2.1",
69-
"tslib": "^2.1.0",
69+
"tslib": "^2.6.0",
7070
"update-electron-app": "^2.0.1"
7171
},
7272
"devDependencies": {
@@ -117,7 +117,7 @@
117117
"eslint-plugin-prettier": "^3.3.1",
118118
"eslint-plugin-react": "^7.22.0",
119119
"fetch-mock-jest": "^1.5.1",
120-
"fork-ts-checker-webpack-plugin": "^7.2.11",
120+
"fork-ts-checker-webpack-plugin": "^8.0.0",
121121
"husky": "^5.1.1",
122122
"jest": "^29.5.0",
123123
"jest-environment-jsdom": "^29.5.0",
@@ -139,8 +139,8 @@
139139
"stylelint-config-standard": "^20.0.0",
140140
"terser-webpack-plugin": "^5.3.3",
141141
"ts-jest": "^29.1.1",
142-
"ts-loader": "^9.3.1",
143-
"typescript": "~4.3.0",
142+
"ts-loader": "^9.4.4",
143+
"typescript": "^5.1.6",
144144
"webpack": "^5.69.1"
145145
},
146146
"lint-staged": {

src/main/windows.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ export function createMainWindow(): Electron.BrowserWindow {
101101
});
102102

103103
ipcMainManager.handle(IpcEvents.GET_APP_PATHS, () => {
104-
const paths = {};
105104
const pathsToQuery = [
106105
'home',
107106
'appData',
@@ -110,6 +109,7 @@ export function createMainWindow(): Electron.BrowserWindow {
110109
'downloads',
111110
'desktop',
112111
] as const;
112+
const paths = {} as Record<typeof pathsToQuery[number], string>;
113113
for (const path of pathsToQuery) {
114114
paths[path] = app.getPath(path);
115115
}

src/renderer/app.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import * as path from 'node:path';
22

33
import { autorun, reaction, when } from 'mobx';
44

5-
import { EditorValues, PACKAGE_NAME, SetFiddleOptions } from '../interfaces';
5+
import {
6+
EditorId,
7+
EditorValues,
8+
PACKAGE_NAME,
9+
SetFiddleOptions,
10+
} from '../interfaces';
611
import { defaultDark, defaultLight } from '../themes-defaults';
712
import { USER_DATA_PATH } from './constants';
813
import { ElectronTypes } from './electron-types';
@@ -92,7 +97,10 @@ export class App {
9297
const values = this.state.editorMosaic.values();
9398

9499
if (options) {
95-
values[PACKAGE_NAME] = await getPackageJson(this.state, options);
100+
values[PACKAGE_NAME as EditorId] = await getPackageJson(
101+
this.state,
102+
options,
103+
);
96104
}
97105

98106
return values;

src/renderer/components/commands-action-button.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ import { when } from 'mobx';
1414
import { observer } from 'mobx-react';
1515

1616
import {
17+
EditorId,
1718
EditorValues,
1819
GistActionState,
1920
GistActionType,
21+
PACKAGE_NAME,
2022
} from '../../interfaces';
2123
import { AppState } from '../state';
2224
import { ensureRequiredFiles } from '../utils/editor-utils';
@@ -125,7 +127,8 @@ export const GistActionButton = observer(
125127
options,
126128
);
127129

128-
defaultGistValues['package.json'] = currentEditorValues['package.json'];
130+
defaultGistValues[PACKAGE_NAME as EditorId] =
131+
currentEditorValues[PACKAGE_NAME as EditorId];
129132

130133
try {
131134
const gistFilesList = appState.isPublishingGistAsRevision

src/renderer/components/output-editors-wrapper.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ export class OutputEditorsWrapper extends React.Component<
5454
public render() {
5555
return (
5656
<Mosaic<WrapperEditorId>
57-
renderTile={(id: string) => this.MOSAIC_ELEMENTS[id]}
57+
renderTile={(id: string) =>
58+
this.MOSAIC_ELEMENTS[id as keyof typeof this.MOSAIC_ELEMENTS]
59+
}
5860
resize={{ minimumPaneSizePercentage: 15 }}
5961
value={this.state.mosaic}
6062
onChange={this.onChange}

src/renderer/components/settings-execution.tsx

+9-12
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,10 @@ import { observer } from 'mobx-react';
1515
import { GlobalSetting, IPackageManager } from '../../interfaces';
1616
import { AppState } from '../state';
1717

18-
/**
19-
* @TODO make this a proper enum again once we update Typescript
20-
*/
21-
export const SettingItemType = {
22-
EnvVars: GlobalSetting.environmentVariables,
23-
Flags: GlobalSetting.executionFlags,
24-
} as const;
18+
export enum SettingItemType {
19+
EnvVars = GlobalSetting.environmentVariables,
20+
Flags = GlobalSetting.executionFlags,
21+
}
2522

2623
interface ExecutionSettingsProps {
2724
appState: AppState;
@@ -118,11 +115,11 @@ export const ExecutionSettings = observer(
118115
* run with the Electron executable.
119116
*
120117
* @param {React.ChangeEvent<HTMLInputElement>} event
121-
* @param {GlobalSetting} type
118+
* @param {SettingItemType} type
122119
*/
123120
public handleSettingsItemChange(
124121
event: React.ChangeEvent<HTMLInputElement>,
125-
type: GlobalSetting,
122+
type: SettingItemType,
126123
) {
127124
const { name, value } = event.currentTarget;
128125

@@ -137,9 +134,9 @@ export const ExecutionSettings = observer(
137134
/**
138135
* Adds a new settings item input field.
139136
*
140-
* @param {GlobalSetting} type
137+
* @param {SettingItemType} type
141138
*/
142-
private addNewSettingsItem(type: GlobalSetting) {
139+
private addNewSettingsItem(type: SettingItemType) {
143140
const array = Object.entries(this.state[type]);
144141

145142
this.setState((prevState) => ({
@@ -163,7 +160,7 @@ export const ExecutionSettings = observer(
163160
appState.packageManager = value as IPackageManager;
164161
};
165162

166-
public renderDeleteItem(idx: string, type: GlobalSetting): JSX.Element {
163+
public renderDeleteItem(idx: string, type: SettingItemType): JSX.Element {
167164
const updated = this.state[type];
168165

169166
const removeFn = () => {

src/renderer/components/sidebar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const Sidebar = ({ appState }: { appState: AppState }) => {
1313
};
1414
return (
1515
<Mosaic<string>
16-
renderTile={(id) => ELEMENT_MAP[id]}
16+
renderTile={(id) => ELEMENT_MAP[id as keyof typeof ELEMENT_MAP]}
1717
initialValue={{
1818
first: 'fileTree',
1919
second: 'packageManager',

src/renderer/file-manager.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as fs from 'fs-extra';
44
import semver from 'semver';
55

66
import {
7+
EditorId,
8+
EditorValues,
79
FileTransform,
810
Files,
911
GenericDialogType,
@@ -70,7 +72,7 @@ export class FileManager {
7072
console.log(`FileManager: Asked to open`, filePath);
7173
if (!filePath || typeof filePath !== 'string') return;
7274

73-
const editorValues = {};
75+
const editorValues: EditorValues = {};
7476
const files: [string, string][] = Object.entries(
7577
await readFiddle(filePath, true),
7678
);
@@ -115,7 +117,7 @@ export class FileManager {
115117
}
116118

117119
if (isKnownFile(name) || (await app.remoteLoader.confirmAddFile(name))) {
118-
editorValues[name] = value;
120+
editorValues[name as EditorId] = value;
119121
}
120122
}
121123

@@ -185,7 +187,7 @@ export class FileManager {
185187

186188
let output: Files = new Map(Object.entries(values));
187189

188-
output.set(PACKAGE_NAME, values[PACKAGE_NAME]!);
190+
output.set(PACKAGE_NAME, values[PACKAGE_NAME as EditorId]!);
189191

190192
for (const transform of transforms) {
191193
try {

src/renderer/remote-loader.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import semver from 'semver';
22

33
import {
4+
EditorId,
45
EditorValues,
56
ElectronReleaseChannel,
67
GenericDialogType,
@@ -27,7 +28,7 @@ export class RemoteLoader {
2728
'setElectronVersion',
2829
'verifyReleaseChannelEnabled',
2930
'verifyRemoteLoad',
30-
]) {
31+
] as const) {
3132
this[name] = this[name].bind(this);
3233
}
3334
}
@@ -100,7 +101,7 @@ export class RemoteLoader {
100101
fetch(child.download_url)
101102
.then((r) => r.text())
102103
.then((t) => {
103-
values[child.name] = t;
104+
values[child.name as EditorId] = t;
104105
}),
105106
);
106107
}

src/renderer/themes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export async function getTheme(
4343
async function getCssStringForTheme(theme: FiddleTheme): Promise<string> {
4444
let cssContent = '';
4545

46-
Object.keys(theme.common).forEach((key) => {
46+
Object.keys(theme.common).forEach((key: keyof typeof theme.common) => {
4747
cssContent += ` --${key}: ${theme.common[key]};\n`;
4848
});
4949

src/utils/editor-utils.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ const EMPTY_EDITOR_CONTENT = {
99
} as const;
1010

1111
export function getEmptyContent(filename: string): string {
12-
return EMPTY_EDITOR_CONTENT[getSuffix(filename)] || '';
12+
return (
13+
EMPTY_EDITOR_CONTENT[
14+
getSuffix(filename) as keyof typeof EMPTY_EDITOR_CONTENT
15+
] || ''
16+
);
1317
}
1418

1519
export function isRequiredFile(id: EditorId) {
@@ -27,6 +31,6 @@ export function getSuffix(filename: string) {
2731
return filename.slice(filename.lastIndexOf('.') + 1);
2832
}
2933

30-
export function isSupportedFile(filename: string): boolean {
34+
export function isSupportedFile(filename: string): filename is EditorId {
3135
return /\.(css|html|js)$/i.test(filename);
3236
}

src/utils/read-fiddle.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'node:path';
22

33
import * as fs from 'fs-extra';
44

5-
import { EditorValues, PACKAGE_NAME } from '../interfaces';
5+
import { EditorId, EditorValues, PACKAGE_NAME } from '../interfaces';
66
import { ensureRequiredFiles, isSupportedFile } from './editor-utils';
77

88
/**
@@ -31,7 +31,7 @@ export async function readFiddle(
3131
);
3232

3333
for (let i = 0; i < names.length; ++i) {
34-
const name = names[i];
34+
const name = names[i] as EditorId;
3535
const value = values[i];
3636

3737
if (value.status === 'fulfilled') {

tests/mocks/electron-versions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class VersionsMock {
1717
version,
1818
}));
1919

20-
const obj = {};
20+
const obj: Record<string, RunnableVersion> = {};
2121
for (const ver of arr) {
2222
obj[ver.version] = ver;
2323
}

tests/mocks/state.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ export class StateMock {
181181
[ver.version, ver.source, ver.state].join(' ');
182182
for (const [key, val] of Object.entries(o)) {
183183
if (key == 'currentElectronVersion') {
184-
o[key] = terserRunnable(val) as any;
184+
o[key] = terserRunnable(val as RunnableVersion);
185185
} else if (key === 'versions') {
186-
o[key] = Object.values(val).map(terserRunnable) as any;
186+
o[key] = Object.values(val as Record<string, RunnableVersion>).map(
187+
terserRunnable,
188+
);
187189
} else if (key === 'versionsToShow') {
188-
o[key] = val.map(terserRunnable);
190+
o[key] = (val as Array<RunnableVersion>).map(terserRunnable);
189191
}
190192
}
191193

tests/renderer/bisect-spec.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,20 @@ describe('bisect', () => {
4848
expect(bisector.revList.length).toBe(2);
4949
const responseGood = bisector.continue(true);
5050
expect(responseGood).toHaveLength(2);
51-
expect(versions).toContain(responseGood[0]);
52-
expect(versions).toContain(responseGood[1]);
51+
if (Array.isArray(responseGood)) {
52+
expect(versions).toContain(responseGood[0]);
53+
expect(versions).toContain(responseGood[1]);
54+
}
5355

5456
bisector = new Bisector(versions);
5557

5658
expect(bisector.revList.length).toBe(2);
5759
const responseBad = bisector.continue(false);
5860
expect(responseBad).toHaveLength(2);
59-
expect(versions).toContain(responseBad[0]);
60-
expect(versions).toContain(responseBad[1]);
61+
if (Array.isArray(responseBad)) {
62+
expect(versions).toContain(responseBad[0]);
63+
expect(versions).toContain(responseBad[1]);
64+
}
6165
});
6266
});
6367

tests/renderer/editor-mosaic-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ describe('EditorMosaic', () => {
227227

228228
// now modify values _after_ calling editorMosaic.set()
229229
for (const [file, value] of Object.entries(values)) {
230-
values[file] = `${value} plus more text`;
230+
values[file as EditorId] = `${value} plus more text`;
231231
}
232232

233233
// and then add Monaco editors

tests/renderer/remote-loader-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ describe('RemoteLoader', () => {
276276

277277
await instance.fetchExampleAndLoad('v4.0.0', 'test/path');
278278

279-
const expectedValues = {};
279+
const expectedValues: Record<string, string> = {};
280280
for (const filename of Object.keys(mockGistFiles)) {
281281
expectedValues[filename] = filename;
282282
}

tests/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ export class FetchMock {
9090
}
9191

9292
// return an object containing props in 'a' that are different from in 'b'
93-
export function objectDifference<Type>(a: Type, b: Type): Type {
93+
export function objectDifference(a: any, b: any): Record<string, unknown> {
9494
const serialize = (input: any) => JSON.stringify(toJS(input));
9595

96-
const o = {};
96+
const o: Record<string, unknown> = {};
9797
for (const entry of Object.entries(a)) {
9898
const key = entry[0];
9999
const val = toJS(entry[1]);
100100
if (serialize(val) == serialize(b[key])) continue;
101101

102102
o[key] = key === 'editorMosaic' ? objectDifference(val, b[key]) : toJS(val);
103103
}
104-
return o as Type;
104+
return o;
105105
}
106106

107107
/**

tests/utils/read-fiddle-spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'node:path';
22

33
import * as fs from 'fs-extra';
44

5-
import { EditorValues, MAIN_JS } from '../../src/interfaces';
5+
import { EditorId, EditorValues, MAIN_JS } from '../../src/interfaces';
66
import {
77
ensureRequiredFiles,
88
getEmptyContent,
@@ -26,7 +26,7 @@ describe('read-fiddle', () => {
2626
function setupFSMocks(editorValues: EditorValues) {
2727
(fs.readdir as jest.Mock).mockResolvedValue(Object.keys(editorValues));
2828
(fs.readFile as jest.Mock).mockImplementation(
29-
async (filename) => editorValues[path.basename(filename)],
29+
async (filename) => editorValues[path.basename(filename) as EditorId],
3030
);
3131
}
3232

tsconfig.json

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
],
1717
"noImplicitAny": true,
1818
"noImplicitReturns": true,
19-
"suppressImplicitAnyIndexErrors": true,
2019
"strictNullChecks": true,
2120
"noUnusedLocals": true,
2221
"noImplicitThis": true,

0 commit comments

Comments
 (0)