https://www.typescriptlang.org/docs/handbook/mixins.html

Typescript에 Mixin 기능은 있는데, 정작 내가 원하는 형태로 지원하는 기능이 아니다. 내가 원하는건 그냥 dart 마냥 클래스의 메서드를 확장하는 것 그 이상 그 이하도 아닌데.... 흑흑...

Dart의 경우


mixin Dog {
  void walk() { ... }
}

mixin Fish {
  void swim() { ... }
}

mixin Bird {
  void fly() { ... }
}

class Animal with Dog, Fish, Bird {
   ...
}

main() {
  final animal = Animal();
  animal.fly();
  animal.swim();
  animal.walk();
}

이런 느낌의 코드를 짜는게 가능하다.

Typescript도 유틸리티성 함수를 묶어서 mixin 문법처럼 매끄럽게 클래스에 포함시킬 수 있는 뭔가가 있었으면 좋겠다.

2

If you have a fediverse account, you can reply to this note from your own instance. Search https://hackers.pub/ap/notes/01990ecc-9828-79a4-9bad-d3ddbfa81460 on your instance and reply to it.

0