Skip to content

Commit 4656dc7

Browse files
feat: 기존 코드에서 타입스크립트 적용 (#110)
1 parent c6905e6 commit 4656dc7

Some content is hidden

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

45 files changed

+995
-523
lines changed

global.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module '*.module.css' {
2+
const content: { [key: string]: string };
3+
export default content;
4+
}
5+
6+
declare module '*.svg' {
7+
import React from 'react';
8+
export const ReactComponent: React.FC<React.SVGProps<SVGSVGElement>>;
9+
const src: string;
10+
export default src;
11+
}

jsconfig.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

package-lock.json

Lines changed: 13 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
"@testing-library/jest-dom": "^5.17.0",
77
"@testing-library/react": "^13.4.0",
88
"@testing-library/user-event": "^13.5.0",
9+
"@types/react": "^18.3.11",
10+
"@types/react-dom": "^18.3.1",
911
"react": "^18.2.0",
1012
"react-dom": "^18.2.0",
1113
"react-router-dom": "^6.26.1",
1214
"react-scripts": "5.0.1",
15+
"typescript": "^5.6.3",
1316
"web-vitals": "^2.1.4"
1417
},
1518
"scripts": {

src/App.jsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/App.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Routes, Route } from 'react-router-dom';
2+
import Home from 'components/Home';
3+
import Items from 'pages/items/Items';
4+
import AddItem from 'pages/additem/AddItem';
5+
import ProductId from 'pages/items/productId/ProductId';
6+
7+
const App = () => {
8+
return (
9+
<div>
10+
<Routes>
11+
<Route path="/" element={<Items />} />
12+
<Route path="/login" element={<Home />} />
13+
<Route path="/signup" element={<Home />} />
14+
<Route path="/signin" element={<Home />} />
15+
<Route path="/items" element={<Items />} />
16+
<Route path="/items/:id" element={<ProductId />} />
17+
<Route path="/additem" element={<AddItem />} />
18+
<Route path="/faq" element={<Home />} />
19+
<Route path="/privacy" element={<Home />} />
20+
<Route path="*" element={<Home />} />
21+
</Routes>
22+
</div>
23+
);
24+
};
25+
26+
export default App;

src/api/fetchData.js renamed to src/api/fetchData.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1-
export const fetchData = async (url, query = {}, method = 'GET', body = null, headers = {}) => {
1+
interface FetchDataOptions {
2+
url: string;
3+
query?: Record<string, any>;
4+
method?: string;
5+
body?: any;
6+
headers?: Record<string, string>;
7+
}
8+
9+
interface FetchDataResult {
10+
data: any;
11+
loading: boolean;
12+
error: any;
13+
}
14+
15+
export const fetchData = async ({
16+
url,
17+
query = {},
18+
method = 'GET',
19+
body = null,
20+
headers = {}
21+
}: FetchDataOptions): Promise<FetchDataResult> => {
222
const queryString = new URLSearchParams(query).toString();
3-
let data, error, loading = true;
23+
let data: any = null;
24+
let error: any = null;
25+
let loading: boolean = true;
426

527
try {
6-
const options = {
28+
const options: RequestInit = {
729
method,
830
headers: {
931
'Content-Type': 'application/json',
@@ -28,3 +50,5 @@ export const fetchData = async (url, query = {}, method = 'GET', body = null, he
2850

2951
return { data, loading, error };
3052
};
53+
54+
export default fetchData;

src/components/Header.jsx renamed to src/components/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ const Header = () => {
4545
);
4646
}
4747

48-
export default Header;
48+
export default Header;
File renamed without changes.

src/components/additem/AddProduct.jsx

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)