interface ProductFilterCallback {
(product: Product): boolean
class ProductRepository {
getMatchingItemList(filter: ProductFilterCallback) {
const productRepository = new ProductRepository();
// error TS2345: Argument of type '(productName: string) => true' is
// not assignable to parameter of type 'ProductFilterCallback'.
// Types of parameters 'productName' and 'product' are incompatible.
// Type 'Product' is not assignable to type 'string'.
productRepository.getMatchingItemList((productName: string) => {
// error TS2345: Argument of type '(product: Product) => string' is
// not assignable to parameter of type 'ProductFilterCallback'
productRepository.getMatchingItemList(product => {
// error TS2339: Property 'name' does not exist on type 'Product'.
productRepository.getMatchingItemList(product => {
return product.name != null;