Typescript: Ковариантность и контравариантность
Задание
Полезное
Loading...
Ваше упражнение проверяется по этим тестам
import { expect, test, expectTypeOf } from 'vitest';
import applyTransactions, { Wallet } from './index';
test('applyTransactions', () => {
const wallet: Wallet = {
balance: 100,
transactions: [
{
apply: (amount: number) => amount + 10,
},
{
apply: (amount: number) => amount - 20,
},
{
apply: (amount: number) => amount + 30,
},
],
};
expect(applyTransactions(wallet)).toBe(120);
expect(wallet.balance).toBe(100);
const wallet2: Wallet = {
balance: 10,
transactions: [
{
apply: (amount: number) => amount + 10,
},
{
apply: () => {
throw new Error('Error');
},
},
{
apply: (amount: number) => amount + 30,
},
],
};
expect(applyTransactions(wallet2)).toBe(10);
expectTypeOf(wallet2.transactions[0].apply).returns.toMatchTypeOf<number>();
});
Решение учителя откроется через:
20:00
