Typescript & Design Patterns | Strategy Pattern - 1

preview_player
Показать описание

Additional Resources:
Head First Designs

Design Patterns: Elements of Reusable Object-Oriented Software

Design Patterns Playlist | Christopher Okhravi

Social Media
Рекомендации по теме
Комментарии
Автор

Thanks. I was trying to achieve this pattern, but I did the mistake of writing `paid<Currency, P: Payment<Currency>>(payment: P)` instead of `paid<Currency>(payment: Payment<Currency>)`. The difference is, that with the former way TypeScript fails to associate `Currency` from the interface to the function. In other words, if I used DollarPayment the function signature would be `paid<unknown, DollarPayment>` instead of `paid<Dollar, DollarPayment>`. Thankfully, this is not an issue with the later way — it will be `paid<Dollar>` there.

TBH, the correct way makes little sense syntax-wise, but I'm happy as long as it works.

mks-h
welcome to shbcf.ru