Skip to content

Commit 9b09ee8

Browse files
committed
Remove typing-tester to use a newer TS version
Former-commit-id: 14555f3 Former-commit-id: 3b733fd
1 parent 766268d commit 9b09ee8

13 files changed

+68
-18
lines changed

jest.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** @type {import('@ts-jest/dist/types').InitialOptionsTsJest} */
2+
module.exports = {
3+
preset: 'ts-jest',
4+
testEnvironment: 'node',
5+
testRegex: '(/test/.*\\.spec\\.ts)$',
6+
coverageProvider: 'v8',
7+
globals: {
8+
'ts-jest': {
9+
tsconfig: './test/tsconfig.json'
10+
}
11+
}
12+
}

package-lock.json.REMOVED.git-id

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json.REMOVED.git-id

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dd100f09e0aa9bf76196b807e3b4edc1c290cefa
1+
7abf8f801ad6278aba4e85685c3d23adefad116a

test/typescript.spec.ts

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a44ec422ce7bb764e33d1e580fb04c6b7d61d904
1+
4fe5391fe6d7d580e3cf9833bd1f2438a4831ee1

test/typescript/dispatch.ts

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Dispatch } from '../..'
2+
3+
/**
4+
* Default Dispatch type accepts any object with `type` property.
5+
*/
6+
function simple() {
7+
const dispatch: Dispatch = null as any
8+
9+
const a = dispatch({ type: 'INCREMENT', count: 10 })
10+
11+
a.count
12+
// @ts-expect-error
13+
a.wrongProp
14+
15+
// @ts-expect-error
16+
dispatch('not-an-action')
17+
}
18+
19+
/**
20+
* Dispatch accepts type argument that restricts allowed action types.
21+
*/
22+
function discriminated() {
23+
interface IncrementAction {
24+
type: 'INCREMENT'
25+
count?: number
26+
}
27+
28+
interface DecrementAction {
29+
type: 'DECREMENT'
30+
count?: number
31+
}
32+
33+
// Union of all actions in the app.
34+
type MyAction = IncrementAction | DecrementAction
35+
36+
const dispatch: Dispatch<MyAction> = null as any
37+
38+
dispatch({ type: 'INCREMENT' })
39+
dispatch({ type: 'DECREMENT', count: 10 })
40+
// Known actions are strictly checked.
41+
// @ts-expect-error
42+
dispatch({ type: 'DECREMENT', count: '' })
43+
// Unknown actions are rejected.
44+
// @ts-expect-error
45+
dispatch({ type: 'SOME_OTHER_TYPE' })
46+
}

test/typescript/dispatch.ts.REMOVED.git-id

-1
This file was deleted.
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c66bac779585048dcb3de7c927e79b3a21fa3005
1+
0ec1bdcfadf9d9bb02aa1d812fdd88b8a3dc4f90
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
46dc9a70160a8144aae157d53f4180200b6e4f13
1+
1517bfa43fbbb3f555e402e5f9acefebec6c52b1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5606f4d91bcebe6566487718f045ef25aa89e7cc
1+
9514050a6c4db705af40e188e2261f5c88e5aa9d
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f013f83b37aaf1bf8d8183e2bc433a454fa56e9b
1+
a482d58a62258498136fbc024a0c39087ccb98f8

test/typescript/replaceReducer.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ store.dispatch(ACTION)
1515

1616
const firstState = store.getState()
1717
firstState.bar.value
18-
// typings:expect-error
18+
// @ts-expect-error
1919
firstState.baz.value
2020

2121
const nextStore = store.replaceReducer(combineReducers({ baz })) // returns -> { baz: { value: 'baz' }}
2222

2323
const nextState = nextStore.getState()
24-
// typings:expect-error
24+
// @ts-expect-error
2525
nextState.bar.value
2626
nextState.baz.value
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
581738858352e6c89926461ccfb08849b31e6d04
1+
f3b18fca8317d774b282c7ef54a9edd3dce7112f

0 commit comments

Comments
 (0)