From a9cb042bd6e27d5e89c310458e7a6a59c8022e1d Mon Sep 17 00:00:00 2001 From: Philip Peterson Date: Mon, 21 Apr 2025 20:45:30 -0700 Subject: [PATCH] Fix typescript errors --- app/commands.ts | 6 ++-- app/menus/menus/edit.ts | 22 +++++++-------- app/menus/menus/shell.ts | 4 +-- app/menus/menus/view.ts | 4 +-- app/menus/menus/window.ts | 4 +-- lib/index.tsx | 2 +- typings/styled.d.ts | 8 ++++++ webpack.config.ts | 58 ++++++++++++++++++++------------------- 8 files changed, 59 insertions(+), 49 deletions(-) create mode 100644 typings/styled.d.ts diff --git a/app/commands.ts b/app/commands.ts index 469a5a3d..df5a512f 100644 --- a/app/commands.ts +++ b/app/commands.ts @@ -1,12 +1,12 @@ import {app, Menu} from 'electron'; -import type {BrowserWindow} from 'electron'; +import type {BaseWindow} from 'electron'; import {openConfig, getConfig} from './config'; import {updatePlugins} from './plugins'; import {installCLI} from './utils/cli-install'; import * as systemContextMenu from './utils/system-context-menu'; -const commands: Record void> = { +const commands: Record void> = { 'window:new': () => { // If window is created on the same tick, it will consume event too setTimeout(app.createWindow, 0); @@ -162,7 +162,7 @@ getConfig().profiles.forEach((profile) => { }; }); -export const execCommand = (command: string, focusedWindow?: BrowserWindow) => { +export const execCommand = (command: string, focusedWindow?: BaseWindow) => { const fn = commands[command]; if (fn) { fn(focusedWindow); diff --git a/app/menus/menus/edit.ts b/app/menus/menus/edit.ts index a9040f6e..1416d594 100644 --- a/app/menus/menus/edit.ts +++ b/app/menus/menus/edit.ts @@ -38,7 +38,7 @@ const editMenu = ( label: 'Select All', accelerator: commandKeys['editor:selectAll'], click(item, focusedWindow) { - execCommand('editor:selectAll', focusedWindow); + execCommand('editor:selectAll', focusedWindow as BrowserWindow | undefined); } }, { @@ -51,28 +51,28 @@ const editMenu = ( label: 'Previous word', accelerator: commandKeys['editor:movePreviousWord'], click(item, focusedWindow) { - execCommand('editor:movePreviousWord', focusedWindow); + execCommand('editor:movePreviousWord', focusedWindow as BrowserWindow | undefined); } }, { label: 'Next word', accelerator: commandKeys['editor:moveNextWord'], click(item, focusedWindow) { - execCommand('editor:moveNextWord', focusedWindow); + execCommand('editor:moveNextWord', focusedWindow as BrowserWindow | undefined); } }, { label: 'Line beginning', accelerator: commandKeys['editor:moveBeginningLine'], click(item, focusedWindow) { - execCommand('editor:moveBeginningLine', focusedWindow); + execCommand('editor:moveBeginningLine', focusedWindow as BrowserWindow | undefined); } }, { label: 'Line end', accelerator: commandKeys['editor:moveEndLine'], click(item, focusedWindow) { - execCommand('editor:moveEndLine', focusedWindow); + execCommand('editor:moveEndLine', focusedWindow as BrowserWindow | undefined); } } ] @@ -84,28 +84,28 @@ const editMenu = ( label: 'Previous word', accelerator: commandKeys['editor:deletePreviousWord'], click(item, focusedWindow) { - execCommand('editor:deletePreviousWord', focusedWindow); + execCommand('editor:deletePreviousWord', focusedWindow as BrowserWindow | undefined); } }, { label: 'Next word', accelerator: commandKeys['editor:deleteNextWord'], click(item, focusedWindow) { - execCommand('editor:deleteNextWord', focusedWindow); + execCommand('editor:deleteNextWord', focusedWindow as BrowserWindow | undefined); } }, { label: 'Line beginning', accelerator: commandKeys['editor:deleteBeginningLine'], click(item, focusedWindow) { - execCommand('editor:deleteBeginningLine', focusedWindow); + execCommand('editor:deleteBeginningLine', focusedWindow as BrowserWindow | undefined); } }, { label: 'Line end', accelerator: commandKeys['editor:deleteEndLine'], click(item, focusedWindow) { - execCommand('editor:deleteEndLine', focusedWindow); + execCommand('editor:deleteEndLine', focusedWindow as BrowserWindow | undefined); } } ] @@ -117,14 +117,14 @@ const editMenu = ( label: 'Clear Buffer', accelerator: commandKeys['editor:clearBuffer'], click(item, focusedWindow) { - execCommand('editor:clearBuffer', focusedWindow); + execCommand('editor:clearBuffer', focusedWindow as BrowserWindow | undefined); } }, { label: 'Search', accelerator: commandKeys['editor:search'], click(item, focusedWindow) { - execCommand('editor:search', focusedWindow); + execCommand('editor:search', focusedWindow as BrowserWindow | undefined); } } ]; diff --git a/app/menus/menus/shell.ts b/app/menus/menus/shell.ts index 651f071c..ca026446 100644 --- a/app/menus/menus/shell.ts +++ b/app/menus/menus/shell.ts @@ -1,8 +1,8 @@ -import type {BrowserWindow, MenuItemConstructorOptions} from 'electron'; +import type {BaseWindow, MenuItemConstructorOptions} from 'electron'; const shellMenu = ( commandKeys: Record, - execCommand: (command: string, focusedWindow?: BrowserWindow) => void, + execCommand: (command: string, focusedWindow?: BaseWindow) => void, profiles: string[] ): MenuItemConstructorOptions => { const isMac = process.platform === 'darwin'; diff --git a/app/menus/menus/view.ts b/app/menus/menus/view.ts index d0a2b071..ae2fe1d0 100644 --- a/app/menus/menus/view.ts +++ b/app/menus/menus/view.ts @@ -1,8 +1,8 @@ -import type {BrowserWindow, MenuItemConstructorOptions} from 'electron'; +import type {BaseWindow, MenuItemConstructorOptions} from 'electron'; const viewMenu = ( commandKeys: Record, - execCommand: (command: string, focusedWindow?: BrowserWindow) => void + execCommand: (command: string, focusedWindow?: BaseWindow) => void ): MenuItemConstructorOptions => { return { label: 'View', diff --git a/app/menus/menus/window.ts b/app/menus/menus/window.ts index 7ae142a6..aad329b1 100644 --- a/app/menus/menus/window.ts +++ b/app/menus/menus/window.ts @@ -1,8 +1,8 @@ -import type {BrowserWindow, MenuItemConstructorOptions} from 'electron'; +import type {BaseWindow, MenuItemConstructorOptions} from 'electron'; const windowMenu = ( commandKeys: Record, - execCommand: (command: string, focusedWindow?: BrowserWindow) => void + execCommand: (command: string, focusedWindow?: BaseWindow) => void ): MenuItemConstructorOptions => { // Generating tab:jump array const tabJump: MenuItemConstructorOptions[] = []; diff --git a/lib/index.tsx b/lib/index.tsx index 3d62015e..99dc88a1 100644 --- a/lib/index.tsx +++ b/lib/index.tsx @@ -1,6 +1,6 @@ import './v8-snapshot-util'; import {webFrame} from 'electron'; -import React from 'react'; +import React, { useMemo } from 'react'; import {createRoot} from 'react-dom/client'; import {Provider} from 'react-redux'; diff --git a/typings/styled.d.ts b/typings/styled.d.ts new file mode 100644 index 00000000..febdbe15 --- /dev/null +++ b/typings/styled.d.ts @@ -0,0 +1,8 @@ +import 'react'; + +declare module 'react' { + interface StyleHTMLAttributes extends React.HTMLAttributes { + jsx?: boolean; + global?: boolean; + } +} diff --git a/webpack.config.ts b/webpack.config.ts index ce95853f..41b43f49 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -69,6 +69,10 @@ const config: webpack.Configuration[] = [ mode: 'none', name: 'hyper', resolve: { + alias: { + react: path.resolve(__dirname, 'node_modules/react'), + 'react-dom': path.resolve(__dirname, 'node_modules/react-dom') + }, extensions: ['.js', '.jsx', '.ts', '.tsx', '.d.ts'] }, devtool: isProd ? 'hidden-source-map' : 'cheap-module-source-map', @@ -96,34 +100,32 @@ const config: webpack.Configuration[] = [ ] }, externals: { - 'color-convert': 'require("./node_modules/color-convert/index.js")', - 'color-string': 'require("./node_modules/color-string/index.js")', - columnify: 'require("./node_modules/columnify/columnify.js")', - lodash: 'require("./node_modules/lodash/lodash.js")', - ms: 'require("./node_modules/ms/index.js")', - 'normalize-url': 'require("./node_modules/normalize-url/index.js")', - 'parse-url': 'require("./node_modules/parse-url/dist/index.js")', - 'php-escape-shell': 'require("./node_modules/php-escape-shell/php-escape-shell.js")', - plist: 'require("./node_modules/plist/index.js")', - 'react-dom': 'require("./node_modules/react-dom/index.js")', - 'react-redux': 'require("./node_modules/react-redux/lib/index.js")', - react: 'require("./node_modules/react/index.js")', - 'redux-thunk': 'require("./node_modules/redux-thunk/lib/index.js")', - redux: 'require("./node_modules/redux/lib/redux.js")', - reselect: 'require("./node_modules/reselect/lib/index.js")', - 'seamless-immutable': 'require("./node_modules/seamless-immutable/src/seamless-immutable.js")', - stylis: 'require("./node_modules/stylis/stylis.js")', - '@xterm/addon-unicode11': 'require("./node_modules/@xterm/addon-unicode11/lib/addon-unicode11.js")', - args: 'require("./node_modules/args/lib/index.js")', - mousetrap: 'require("./node_modules/mousetrap/mousetrap.js")', - open: 'require("./node_modules/open/index.js")', - '@xterm/addon-fit': 'require("./node_modules/@xterm/addon-fit/lib/addon-fit.js")', - '@xterm/addon-image': 'require("./node_modules/@xterm/addon-image/lib/addon-image.js")', - '@xterm/addon-search': 'require("./node_modules/@xterm/addon-search/lib/addon-search.js")', - '@xterm/addon-web-links': 'require("./node_modules/@xterm/addon-web-links/lib/addon-web-links.js")', - '@xterm/addon-webgl': 'require("./node_modules/@xterm/addon-webgl/lib/addon-webgl.js")', - '@xterm/addon-canvas': 'require("./node_modules/@xterm/addon-canvas/lib/addon-canvas.js")', - xterm: 'require("./node_modules/xterm/lib/xterm.js")' + 'color-convert': 'commonjs color-convert', + 'color-string': 'commonjs color-string', + columnify: 'commonjs columnify', + lodash: 'commonjs lodash', + ms: 'commonjs ms', + 'normalize-url': 'commonjs normalize-url', + 'parse-url': 'commonjs parse-url', + 'php-escape-shell': 'commonjs php-escape-shell', + plist: 'commonjs plist', + // 'react-dom': 'commonjs react-dom', + 'redux-thunk': 'commonjs redux-thunk', + redux: 'commonjs redux', + reselect: 'commonjs reselect', + 'seamless-immutable': 'commonjs seamless-immutable', + stylis: 'commonjs stylis', + '@xterm/addon-unicode11': 'commonjs @xterm/addon-unicode11', + args: 'commonjs args', + mousetrap: 'commonjs mousetrap', + open: 'commonjs open', + '@xterm/addon-fit': 'commonjs @xterm/addon-fit', + '@xterm/addon-image': 'commonjs @xterm/addon-image', + '@xterm/addon-search': 'commonjs @xterm/addon-search', + '@xterm/addon-web-links': 'commonjs @xterm/addon-web-links', + '@xterm/addon-webgl': 'commonjs @xterm/addon-webgl', + '@xterm/addon-canvas': 'commonjs @xterm/addon-canvas', + xterm: 'commonjs xterm' }, plugins: [ new webpack.IgnorePlugin({resourceRegExp: /.*\.js.map$/i}),