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

lecture7 #10

Open
1 task
4BFC opened this issue Aug 17, 2024 · 0 comments
Open
1 task

lecture7 #10

4BFC opened this issue Aug 17, 2024 · 0 comments
Assignees

Comments

@4BFC
Copy link
Member

4BFC commented Aug 17, 2024

  • generic과 interface를 유연하게 사용할 수 있는 방법을 찾아본다.
  • generic을 interface로 직접 만들 수 도 있다.
      // Common 인터페이스 정의
      interface Common {
        name: string;
      }
      
      // 제네릭 타입 매개변수를 Common으로 지정
      function showName<T extends Common>(data: T): string {
        return data.name;
      }
      
      // 사용 예시
      const user = { name: "a", age: 10 };
      const car = { name: "bmw", color: "red" };
      const book = { name: "TypeScript Handbook", price: 3000 };
      
      console.log(showName(user)); // 출력: "a"
      console.log(showName(car));  // 출력: "bmw"
      console.log(showName(book)); // 출력: "TypeScript Handbook"
    

index

@4BFC 4BFC added this to the 코딩앙마 milestone Aug 17, 2024
@4BFC 4BFC self-assigned this Aug 17, 2024
@4BFC 4BFC removed this from the 코딩앙마 milestone Aug 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant