Skip to content

Commit 0fcf75a

Browse files
authored
Only apply mapped types to un-branded types (reduxjs#3805)
Former-commit-id: f361cc1
1 parent 70198f9 commit 0fcf75a

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

index.d.ts.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
50e8d018faee8887ed82337fcd1993ad07df0968
1+
4e03686da367beb6cf54cd98b3fd0dc03a3bb4cd

package-lock.json.REMOVED.git-id

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
"rollup-plugin-replace": "^2.2.0",
8585
"rollup-plugin-terser": "^5.1.1",
8686
"rxjs": "^6.5.2",
87-
"typescript": "^3.5.3",
87+
"typescript": "^3.9.6",
8888
"typings-tester": "^0.3.2"
8989
},
9090
"npmName": "redux",

test/typescript/store.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ import {
1111
} from 'redux'
1212
import 'symbol-observable'
1313

14+
type BrandedString = string & { _brand: 'type' }
15+
const brandedString = 'a string' as BrandedString
16+
1417
type State = {
1518
a: 'a'
1619
b: {
1720
c: 'c'
1821
d: 'd'
1922
}
23+
c: BrandedString
2024
}
2125

2226
interface DerivedAction extends Action {
@@ -30,7 +34,8 @@ const reducer: Reducer<State> = (
3034
b: {
3135
c: 'c',
3236
d: 'd'
33-
}
37+
},
38+
c: brandedString
3439
},
3540
action: Action
3641
): State => {
@@ -43,7 +48,8 @@ const reducerWithAction: Reducer<State, DerivedAction> = (
4348
b: {
4449
c: 'c',
4550
d: 'd'
46-
}
51+
},
52+
c: brandedString
4753
},
4854
action: DerivedAction
4955
): State => {
@@ -58,17 +64,20 @@ const store: Store<State> = createStore(reducer)
5864

5965
const storeWithPreloadedState: Store<State> = createStore(reducer, {
6066
a: 'a',
61-
b: { c: 'c', d: 'd' }
67+
b: { c: 'c', d: 'd' },
68+
c: brandedString
6269
})
6370
// typings:expect-error
6471
const storeWithBadPreloadedState: Store<State> = createStore(reducer, {
65-
b: { c: 'c' }
72+
b: { c: 'c' },
73+
c: brandedString
6674
})
6775

6876
const storeWithActionReducer = createStore(reducerWithAction)
6977
const storeWithActionReducerAndPreloadedState = createStore(reducerWithAction, {
7078
a: 'a',
71-
b: { c: 'c', d: 'd' }
79+
b: { c: 'c', d: 'd' },
80+
c: brandedString
7281
})
7382
funcWithStore(storeWithActionReducer)
7483
funcWithStore(storeWithActionReducerAndPreloadedState)
@@ -77,7 +86,8 @@ funcWithStore(storeWithActionReducerAndPreloadedState)
7786
const storeWithActionReducerAndBadPreloadedState = createStore(
7887
reducerWithAction,
7988
{
80-
b: { c: 'c' }
89+
b: { c: 'c' },
90+
c: brandedString
8191
}
8292
)
8393

@@ -89,7 +99,8 @@ const storeWithPreloadedStateAndEnhancer: Store<State> = createStore(
8999
reducer,
90100
{
91101
a: 'a',
92-
b: { c: 'c', d: 'd' }
102+
b: { c: 'c', d: 'd' },
103+
c: brandedString
93104
},
94105
enhancer
95106
)

0 commit comments

Comments
 (0)