fix type of selectors w/ subduxes
This commit is contained in:
parent
a6b6a54c72
commit
e4083645bc
@ -5,7 +5,7 @@ import Updux, { createAction } from './index.js';
|
|||||||
describe('basic selectors', () => {
|
describe('basic selectors', () => {
|
||||||
type State = { x: number };
|
type State = { x: number };
|
||||||
|
|
||||||
const foo = new Updux({
|
const config = {
|
||||||
initialState: {
|
initialState: {
|
||||||
x: 1,
|
x: 1,
|
||||||
},
|
},
|
||||||
@ -23,8 +23,16 @@ describe('basic selectors', () => {
|
|||||||
(y + incr) as number,
|
(y + incr) as number,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
// cause the type to fail
|
||||||
|
baz: new Updux({
|
||||||
|
selectors: {
|
||||||
|
getFromBaz: () => 'potato',
|
||||||
},
|
},
|
||||||
});
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const foo = new Updux(config);
|
||||||
|
|
||||||
const sample = {
|
const sample = {
|
||||||
x: 4,
|
x: 4,
|
||||||
|
@ -17,9 +17,11 @@ type Values<X> = X[keyof X];
|
|||||||
|
|
||||||
export type DuxSelectors<D> = (D extends { selectors: infer S } ? S : {}) &
|
export type DuxSelectors<D> = (D extends { selectors: infer S } ? S : {}) &
|
||||||
(D extends { subduxes: infer SUB }
|
(D extends { subduxes: infer SUB }
|
||||||
? Values<{
|
? UnionToIntersection<
|
||||||
|
Values<{
|
||||||
[key in keyof SUB]: RebaseSelectors<key, SUB[key]>;
|
[key in keyof SUB]: RebaseSelectors<key, SUB[key]>;
|
||||||
}>
|
}>
|
||||||
|
>
|
||||||
: {});
|
: {});
|
||||||
|
|
||||||
export function buildSelectors(localSelectors = {}, subduxes = {}) {
|
export function buildSelectors(localSelectors = {}, subduxes = {}) {
|
||||||
|
Loading…
Reference in New Issue
Block a user