Skip to content

Commit c8c0da6

Browse files
committed
Migrate type tests in lruMemoize.test-d.ts to Vitest
1 parent 8943a55 commit c8c0da6

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

type-tests/lruMemoize.test-d.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ describe('type tests', () => {
1212

1313
const memoized = lruMemoize(func)
1414

15-
const ret0: number = memoized('42')
16-
// @ts-expect-error
17-
const ret1: string = memoized('42')
15+
expectTypeOf(memoized('42')).toBeNumber()
16+
17+
expectTypeOf(memoized('42')).not.toBeString()
1818

1919
const memoized2 = lruMemoize(
2020
(str: string, arr: string[]): { str: string; arr: string[] } => ({
@@ -27,8 +27,10 @@ describe('type tests', () => {
2727
)
2828

2929
const ret2 = memoized2('', ['1', '2'])
30-
const str: string = ret2.str
31-
const arr: string[] = ret2.arr
30+
31+
expectTypeOf(ret2.str).toBeString()
32+
33+
expectTypeOf(ret2.arr).items.toBeString()
3234
})
3335

3436
test('issue #384', () => {
@@ -40,21 +42,22 @@ describe('type tests', () => {
4042
b: string,
4143
equalityCheck = referenceEqualityCheck
4244
): F {
43-
// @ts-ignore
44-
return () => {}
45+
return func
4546
}
4647

4748
interface Transaction {
4849
transactionId: string
4950
}
5051

5152
const toId = (transaction: Transaction) => transaction.transactionId
53+
5254
const transactionsIds = (transactions: Transaction[]) =>
5355
transactions.map(toId)
56+
5457
const collectionsEqual = (ts1: Transaction[], ts2: Transaction[]) =>
5558
isEqual(transactionsIds(ts1), transactionsIds(ts2))
5659

57-
const createTransactionsSelector = createSelectorCreator(
60+
expectTypeOf(createSelectorCreator).toBeCallableWith(
5861
lruMemoize,
5962
collectionsEqual
6063
)
@@ -70,8 +73,9 @@ describe('type tests', () => {
7073
(state: { foo: string }) => state.foo,
7174
foo => `${foo}!`
7275
)
76+
7377
// error is not applicable anymore
74-
select.clearCache()
78+
expectTypeOf(select.clearCache).toBeFunction()
7579

7680
const createMultiMemoizeArgSelector2 = createSelectorCreator(
7781
multiArgMemoize,
@@ -80,7 +84,7 @@ describe('type tests', () => {
8084
referenceEqualityCheck
8185
)
8286

83-
const groupTransactionsByLabel = lruMemoize(
87+
expectTypeOf(lruMemoize).toBeCallableWith(
8488
(transactions: Transaction[]) =>
8589
groupBy(transactions, item => item.transactionId),
8690
collectionsEqual

0 commit comments

Comments
 (0)