Skip to content

Commit

Permalink
Fix all TypeScript errors so far
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Aug 17, 2024
1 parent bc960bc commit 2653058
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 15 deletions.
5 changes: 4 additions & 1 deletion thallium-frontend/eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ export default tseslint.config(
{ allowConstantExport: true },
],
...react.configs.recommended.rules,
...react.configs['jsx-runtime'].rules
...react.configs['jsx-runtime'].rules,
'@typescript-eslint/no-empty-object-type': ["error", {
allowInterfaces: 'with-single-extends',
}]
},
},
)
5 changes: 2 additions & 3 deletions thallium-frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RouterProvider,
} from "react-router-dom";

import themes from './themes.tsx';
import themes from './themes';

import Header from "./components/Header";

Expand Down Expand Up @@ -68,8 +68,7 @@ function App() {
const theme = isDarkMode ? themes.dark : themes.light;

useEffect(() => {
const prefersDark = window.matchMedia &&
window.matchMedia('(prefers-color-scheme: dark)').matches;
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;

setIsDarkMode(prefersDark);
}, []);
Expand Down
3 changes: 1 addition & 2 deletions thallium-frontend/src/components/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from 'styled-components';


const CardContainer = styled.div`
border: 3px solid ${({ theme }) => theme.borderColor};
padding: 16px;
Expand Down Expand Up @@ -28,7 +27,7 @@ interface CardProps {
children: React.ReactNode;
}

const Card: React.FC<CardProps> = ({ title, children }) => {
const Card: React.FC<CardProps> = ({ title, children }: CardProps) => {
return (
<CardContainer>
<CardTitle>{title}</CardTitle>
Expand Down
26 changes: 18 additions & 8 deletions thallium-frontend/src/pages/ErrorPage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import { useRouteError } from 'react-router-dom';
import { useRouteError, isRouteErrorResponse } from 'react-router-dom';

import Card from '../components/Card';

const LandingPage = () => {
const error: any = useRouteError() || {};
const error = useRouteError();

let title, message, isUnexpected = false;
let title = 'Unexpected Error', message, isUnexpected = false;

if (error.status === 404) {
title = 'Not Found';
message = 'The requested page could not be found.';
if (isRouteErrorResponse(error)) {
if (error.status === 404) {
title = 'Not Found';
message = 'The requested page could not be found.';
} else {
message = error.statusText;
}
} else if (error instanceof Error) {
message = error.message;
isUnexpected = true;
} else if (typeof error === 'string') {
message = error;
isUnexpected = true;
} else {
title = 'Error';
message = error.message || error.statusText;
console.error(error);
message = 'Unknown error';
isUnexpected = true;
}

Expand Down
5 changes: 5 additions & 0 deletions thallium-frontend/src/styled-components.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Theme } from './themes';

declare module "styled-components" {
export interface DefaultTheme extends Theme { }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
const themes = {
interface Theme {
backgroundColor: string;
textColor: string;
borderColor: string;
linkColor: string;
cardBackgroundColor: string;
cardShadow: string;
}

interface ThemesStore {
light: Theme;
dark: Theme;
}

const themes: ThemesStore = {
light: {
backgroundColor: '#f0f0f0',
textColor: '#000',
Expand All @@ -18,3 +32,5 @@ const themes = {
};

export default themes;

export type { Theme, ThemesStore };

0 comments on commit 2653058

Please sign in to comment.