From bfd2ea2094f4b898c342d28c69cc452677dc84ac Mon Sep 17 00:00:00 2001 From: Declan Chidlow Date: Sat, 13 Jul 2024 20:18:12 +0800 Subject: [PATCH] Update typescript configs --- api/tsconfig.json | 20 +++++---- web/src/App.tsx | 6 +-- web/src/components/CategorySelector.tsx | 2 +- .../pages/ServerDashboard/ServerDashboard.tsx | 14 +++---- web/tsconfig.json | 42 +++++++++++++------ 5 files changed, 53 insertions(+), 31 deletions(-) diff --git a/api/tsconfig.json b/api/tsconfig.json index 80cf85c..1ac58a3 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -1,28 +1,32 @@ { "compilerOptions": { // Enable latest features - "lib": ["ESNext", "DOM"], + "lib": ["ESNext", "DOM", "DOM.Iterable"], "target": "ESNext", "module": "ESNext", "moduleDetection": "force", "jsx": "react-jsx", "allowJs": true, - // Bundler mode "moduleResolution": "bundler", "allowImportingTsExtensions": true, "verbatimModuleSyntax": true, "noEmit": true, - // Best practices "strict": true, "skipLibCheck": true, "noFallthroughCasesInSwitch": true, - - // Some stricter flags (disabled by default) - "noUnusedLocals": false, - "noUnusedParameters": false, - "noPropertyAccessFromIndexSignature": false + // Some stricter flags (enabled) + "noUnusedLocals": true, + "noUnusedParameters": true, + "noPropertyAccessFromIndexSignature": true, + // Additional improvements + "esModuleInterop": true, + "resolveJsonModule": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "useDefineForClassFields": true, + "types": ["bun-types"] }, "include": ["src/**/*"], "exclude": ["node_modules", "dist"] diff --git a/web/src/App.tsx b/web/src/App.tsx index d0788fe..35c9fae 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -1,4 +1,4 @@ -import { Route, BrowserRouter, Routes, useLocation } from 'react-router-dom'; +import { Route, BrowserRouter, Routes } from 'react-router-dom'; import Home from './pages/Home'; import './App.css'; import '@revoltchat/ui/src/styles/dark.css'; @@ -9,10 +9,10 @@ import ServerDashboard from './pages/ServerDashboard/ServerDashboard'; import localforage from 'localforage'; import TexPage from './pages/Tex'; -const API_URL = import.meta.env.VITE_API_URL?.toString() +const API_URL = import.meta.env['VITE_API_URL']?.toString() || 'http://localhost:9000'; -const BOT_PREFIX = import.meta.env.VITE_BOT_PREFIX?.toString() +const BOT_PREFIX = import.meta.env['VITE_BOT_PREFIX']?.toString() || '/'; function App() { diff --git a/web/src/components/CategorySelector.tsx b/web/src/components/CategorySelector.tsx index c180fbc..6b18561 100644 --- a/web/src/components/CategorySelector.tsx +++ b/web/src/components/CategorySelector.tsx @@ -1,4 +1,4 @@ -import { FunctionComponent, useState } from "react"; +import { FunctionComponent } from "react"; import './styles/CategorySelector.css'; const CategorySelector: FunctionComponent<{ keys: { id: string, name: string }[], selected: string, onChange: (key: string) => void }> = (props) => { diff --git a/web/src/pages/ServerDashboard/ServerDashboard.tsx b/web/src/pages/ServerDashboard/ServerDashboard.tsx index 8e6c6ae..b5deda0 100644 --- a/web/src/pages/ServerDashboard/ServerDashboard.tsx +++ b/web/src/pages/ServerDashboard/ServerDashboard.tsx @@ -106,14 +106,14 @@ const ServerDashboard: FunctionComponent = () => { const server: Server = res.data.server; setServerInfo(server); - setPrefix(server.serverConfig?.prefix || ''); - setPrefixAllowSpace(!!server.serverConfig?.spaceAfterPrefix); - setDmOnKick(!!server.serverConfig?.dmOnKick); - setDmOnWarn(!!server.serverConfig?.dmOnWarn); - setContact(server.serverConfig?.contact || ''); + setPrefix(server.serverConfig?.['prefix'] || ''); + setPrefixAllowSpace(!!server.serverConfig?.['spaceAfterPrefix']); + setDmOnKick(!!server.serverConfig?.['dmOnKick']); + setDmOnWarn(!!server.serverConfig?.['dmOnWarn']); + setContact(server.serverConfig?.['contact'] || ''); - setBotManagers(server.serverConfig?.botManagers ?? []); - setModerators(server.serverConfig?.moderators ?? []); + setBotManagers(server.serverConfig?.['botManagers'] ?? []); + setModerators(server.serverConfig?.['moderators'] ?? []); loadAutomodInfo(server); } catch(e: any) { diff --git a/web/tsconfig.json b/web/tsconfig.json index 9f83659..30b8d20 100644 --- a/web/tsconfig.json +++ b/web/tsconfig.json @@ -1,20 +1,38 @@ { "compilerOptions": { + // Enable latest features + "lib": ["ESNext", "DOM", "DOM.Iterable"], "target": "ESNext", - "useDefineForClassFields": true, - "lib": ["DOM", "DOM.Iterable", "ESNext"], - "allowJs": false, - "skipLibCheck": false, - "esModuleInterop": false, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, "module": "ESNext", - "moduleResolution": "Node", + "jsx": "react-jsx", + "allowJs": true, + + // Bundler mode + "moduleResolution": "Node", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + + // Best practices + "strict": true, + "skipLibCheck": true, + "noEmit": true, + + // Some stricter flags (enabled) + "noUnusedLocals": true, + "noUnusedParameters": true, + "noPropertyAccessFromIndexSignature": true, + + // Additional improvements + "useDefineForClassFields": true, + "allowSyntheticDefaultImports": true, "resolveJsonModule": true, "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx" + "baseUrl": ".", + "paths": { + "@/*": ["./src/*"] + }, + "incremental": true }, - "include": ["./src"] + "include": ["./src/**/*"], + "exclude": ["node_modules", "dist"] }