From 2518645a1394e21db8899462dae899828907c80a Mon Sep 17 00:00:00 2001 From: juchanhwang Date: Thu, 23 Jul 2020 21:30:20 +0900 Subject: [PATCH 1/2] feat(src/tsconfig): add typescript --- front-empathy/package.json | 3 +- front-empathy/src/api/index.ts | 2 +- .../pages/LocationDetail/LocationDetail.jsx | 34 +++++++++---------- front-empathy/src/react-app-env.d.ts | 1 + front-empathy/tsconfig.json | 25 ++++++++++++++ 5 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 front-empathy/src/react-app-env.d.ts create mode 100644 front-empathy/tsconfig.json diff --git a/front-empathy/package.json b/front-empathy/package.json index 05f8d3f..28bb0c5 100644 --- a/front-empathy/package.json +++ b/front-empathy/package.json @@ -56,7 +56,8 @@ "framer": "^1" }, "devDependencies": { - "framer": "^1.1.7" + "framer": "^1.1.7", + "typescript": "^3.9.6" }, "framer": { "displayName": "" diff --git a/front-empathy/src/api/index.ts b/front-empathy/src/api/index.ts index 903c6a0..52a921d 100644 --- a/front-empathy/src/api/index.ts +++ b/front-empathy/src/api/index.ts @@ -1,6 +1,6 @@ const SERVER_URL = process.env.REACT_APP_SERVER_API; -export const requestGET = (url) => { +export const requestGET = (url: string) => { return fetch(SERVER_URL + url) .then(res => res.json()) .catch(err => console.error(err)); diff --git a/front-empathy/src/pages/LocationDetail/LocationDetail.jsx b/front-empathy/src/pages/LocationDetail/LocationDetail.jsx index b8c1a41..b4505db 100644 --- a/front-empathy/src/pages/LocationDetail/LocationDetail.jsx +++ b/front-empathy/src/pages/LocationDetail/LocationDetail.jsx @@ -17,7 +17,7 @@ const fetchData = (url) => { } export const getLocationId = (locationId) => { - return fetchData(`http://localhost:5000/locationDetail/${locationId}`); + return fetchData(`http://localhost:5000/locationDetail/${ locationId }`); }; const HeroSection = styled.div` @@ -137,7 +137,7 @@ const LocationDetail = ({ firebase, match: { params: { locationId } } }) => { const [loading, setLoading] = useState(true); const setLocationDetail = async () => { - const response = await fetch(`http://localhost:5000/locationDetail/${locationId}`); + const response = await fetch(`http://localhost:5000/locationDetail/${ locationId }`); const initialData = await response.json(); setLocation(initialData); setLoading(false); @@ -164,51 +164,51 @@ const LocationDetail = ({ firebase, match: { params: { locationId } } }) => { return ( <> - {loading ? ( + { loading ? ( ) : ( <> - +
-

{location.name}

+

{ location.name }

-

{location.name}

-

{location.name}

+

{ location.name }

+

{ location.name }

- +
Address - {location.address} + { location.address }
ProgrammeType - {location.programmeType} + { location.programmeType }
Location Fee - {location.fee} + { location.fee }
Opening Hour - {location.openHour} + { location.openHour }
Istagram - {location.instaId} + { location.instaId }
- shareLink(`locationDetail`, `locationDetail`)}/> + shareLink(`locationDetail`, `locationDetail`) }/> @@ -229,18 +229,18 @@ const LocationDetail = ({ firebase, match: { params: { locationId } } }) => { - +
- {events.map(event => )} + { events.map(event => ) }
- )} + ) } ); } diff --git a/front-empathy/src/react-app-env.d.ts b/front-empathy/src/react-app-env.d.ts new file mode 100644 index 0000000..6431bc5 --- /dev/null +++ b/front-empathy/src/react-app-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/front-empathy/tsconfig.json b/front-empathy/tsconfig.json new file mode 100644 index 0000000..f2850b7 --- /dev/null +++ b/front-empathy/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": [ + "dom", + "dom.iterable", + "esnext" + ], + "allowJs": true, + "skipLibCheck": true, + "esModuleInterop": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "module": "esnext", + "moduleResolution": "node", + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + "jsx": "react" + }, + "include": [ + "src" + ] +} From 462a2f7b05debd483656c3fd95f7ded12cee7722 Mon Sep 17 00:00:00 2001 From: juchanhwang Date: Thu, 23 Jul 2020 22:06:57 +0900 Subject: [PATCH 2/2] feat(tsconfig): add typeRoots, types, and include & add global typings path and add interfaces --- front-empathy/tsconfig.json | 10 +++++++++- front-empathy/tslint.json | 5 +++++ front-empathy/typings/index.d.ts | 15 +++++++++++++++ front-empathy/typings/location.d.ts | 18 ++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 front-empathy/tslint.json create mode 100644 front-empathy/typings/index.d.ts create mode 100644 front-empathy/typings/location.d.ts diff --git a/front-empathy/tsconfig.json b/front-empathy/tsconfig.json index f2850b7..7f9d1d0 100644 --- a/front-empathy/tsconfig.json +++ b/front-empathy/tsconfig.json @@ -1,6 +1,13 @@ { "compilerOptions": { "target": "es5", + "typeRoots": [ + "../../node_modules/@types", + "../../typings" + ], + "types": [ + "node" + ], "lib": [ "dom", "dom.iterable", @@ -20,6 +27,7 @@ "jsx": "react" }, "include": [ - "src" + "src", + "**/*.d.ts" ] } diff --git a/front-empathy/tslint.json b/front-empathy/tslint.json new file mode 100644 index 0000000..9109690 --- /dev/null +++ b/front-empathy/tslint.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-reference": false + } +} diff --git a/front-empathy/typings/index.d.ts b/front-empathy/typings/index.d.ts new file mode 100644 index 0000000..ca56963 --- /dev/null +++ b/front-empathy/typings/index.d.ts @@ -0,0 +1,15 @@ +/// + +export declare global { + interface Window { + } + + interface StringKeyDict { + [key: string]: T; + } + + interface NumberKeyDict { + [key: number]: T; + } + +} diff --git a/front-empathy/typings/location.d.ts b/front-empathy/typings/location.d.ts new file mode 100644 index 0000000..793c001 --- /dev/null +++ b/front-empathy/typings/location.d.ts @@ -0,0 +1,18 @@ +export declare global { + interface LocationDetail { + id: string, + name: string; + image: string; + description: string; + address: string; + programmeType: string; + fee: string + openHour: string; + instaId: string; + eventGroup: EventGroup[] + } + + interface EventGroup { + date: string; + } +}