Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[정원식] Sprint 8 #251

Conversation

wonsik3686
Copy link
Collaborator

요구사항

기본

스프린트 미션 1 ~ 7에 대해 typescript를 적용해주세요.

@wonsik3686 wonsik3686 requested a review from arthurkimdev August 2, 2024 14:48
@wonsik3686 wonsik3686 self-assigned this Aug 2, 2024
@wonsik3686 wonsik3686 added 매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. 미완성🫠 죄송합니다.. labels Aug 2, 2024
Comment on lines +35 to +36
const handleDeleteTag = (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
onRemove((e.currentTarget.parentNode as HTMLElement).dataset.tagName || '');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MouseEvent 내부는 아래처럼 생겨서 HTMLElement 값이 T 제너릭에 위치하고, MouseEvent 값이 E 제너릭에 위치해서 UIEvent<HTMLButtonElement, MouseEvent> 로 변경되며 일반적인 UI 이벤트 속성을 상속 받게 되는거예요.

즉 아래처럼 되면서 동작하게 됩니다.

interface MouseEvent<HTMLElement, MouseEvent > extends UIEvent<HTMLElement, MouseEvent> {

아래는 React에서 제공하는 MouseEvent 타입이에요. 예시라서 실제 코드와는 다소 다를 수 있습니다.

interface MouseEvent<T = Element, E = NativeMouseEvent> extends UIEvent<T, E> {
    altKey: boolean;
    button: number;
    buttons: number;
    clientX: number;
    clientY: number;
    ctrlKey: boolean;
    metaKey: boolean;
    movementX: number;
    ...
    getModifierState(key: string): boolean;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이외에 추가적으로 사용하신 React.KeyboardEvent 도 비슷한 원리로 동작합니다. 🙂

Comment on lines 12 to 13
onChange: any;
onChange: (name: string, value: any) => void;
}
Copy link
Collaborator

@arthurkimdev arthurkimdev Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

현재 해당 파일만 봤을 때는 onChange 타입이 아래처럼 변경할 수 있겠네요!
File 타입은 TypeScript가 기본적으로 제공하는 타입 정의 파일 (lib.dom.d.ts)에 포함되어 있기 때문에, 별도의 import 없이 사용할 수 있습니다.

interface ImageFileInputProps {
  className?: string;
  name: string;
  value: Blob | MediaSource | null;
  initialPreview: string;
  onChange: (name: string, value: File | null) => void;
}

Comment on lines 3 to 4
export interface GetProductsProps {
order: 'recent' | 'favorite';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

type OrderType = 'recent' | 'favorite';

위처럼 별도로 정의 후 사용하게 되면 기존코드와 기능적으로는 동일하지만, 해당 타입을 다른 곳에서 재사용 할 수 있겠죠?

export interface GetProductsProps {
  order: OrderType;
  // ... 다른 속성들
}

Comment on lines 4 to 12
interface ButtonProps {
text?: string;
onClick?: (e: React.MouseEvent<HTMLElement, MouseEvent>) => void;
isDisabled?: boolean;
iconFront?: React.ReactNode;
iconBack?: React.ReactNode;
customBorderRound?: any;
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

customBorderRound 값은 사용하지 않는 값이라 제거해도 될 것 같은데요!? 🤖

e.preventDefault();

navigate(`/items/${e.currentTarget.dataset.itemId}`);
};

const fetchItemList = async ({ order, page, pageSize, keyword }) => {
const fetchItemList = async ({
order,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기서 미리 정의한 type OrderType = 'recent' | 'favorite' 값을 가져오면 되겠네요!

Copy link
Collaborator

@arthurkimdev arthurkimdev Aug 4, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아래 다른 값들도 처음 js -> ts 전환할때 any 로 시작하는 방법 좋구요. 👍 천천히 바꿔나가시면 됩니다.

Comment on lines +1 to +18
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

린트 설정 굳! 👍

Comment on lines +1 to +20
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tsconfig 설정 잘하셨습니다.
각각 어떤 의미가 있는지 공부해보면 좋겠어요. 🙂
컴파일 대상 파일들을 어떻게 변환할지 다양한 옵션들이 많거든요.

https://www.typescriptlang.org/tsconfig/

Copy link
Collaborator

@arthurkimdev arthurkimdev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타입스크립트 적용하시느라 수고 많으셨습니다! 🙏

@arthurkimdev arthurkimdev merged commit 0c553b8 into codeit-bootcamp-frontend:React-정원식 Aug 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
매운맛🔥 뒤는 없습니다. 그냥 필터 없이 말해주세요. 책임은 제가 집니다. 미완성🫠 죄송합니다..
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants