@mic-rexjs/usecases-react 2.9.5 → 2.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -591,6 +591,23 @@ describe('useUseCase', () => {
|
|
|
591
591
|
});
|
|
592
592
|
expect(result.current[0].path).toBe('123/' + PATH_1);
|
|
593
593
|
});
|
|
594
|
+
test('Option functions: use `T` (not `S`) when `S extends T`', () => {
|
|
595
|
+
const testObjectUseCase = (options = {}) => {
|
|
596
|
+
const objectReducers = objectUseCase();
|
|
597
|
+
void options;
|
|
598
|
+
return { ...objectReducers };
|
|
599
|
+
};
|
|
600
|
+
renderHook(() => {
|
|
601
|
+
useUseCase(defaultFile, testObjectUseCase, {
|
|
602
|
+
onUpdate(data) {
|
|
603
|
+
void data;
|
|
604
|
+
return Promise.reject();
|
|
605
|
+
},
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
// 这个测试仅仅是为了确保类型不会报错,不验证实际逻辑
|
|
609
|
+
expect(1).toBe(1);
|
|
610
|
+
});
|
|
594
611
|
test('when `options` has changed, it should not trigger update', () => {
|
|
595
612
|
const onUpdate = jest.fn();
|
|
596
613
|
const onDeepUpdate = jest.fn();
|
|
@@ -45,7 +45,11 @@ export interface UseCaseHookContextualOptions<T> {
|
|
|
45
45
|
export interface UseCaseHookOwnOptions<T, TUseCaseOptions extends object> extends UseCaseHookContextualOptions<T> {
|
|
46
46
|
options?: TUseCaseOptions;
|
|
47
47
|
}
|
|
48
|
-
export type
|
|
48
|
+
export type UnextendFunctionTypes<T> = T extends (...args: infer TArgs) => infer TReturn ? (...args: TArgs) => TReturn : T;
|
|
49
|
+
export type UnextendOptionTypes<T> = {
|
|
50
|
+
[K in keyof T]: UnextendFunctionTypes<T[K]>;
|
|
51
|
+
};
|
|
52
|
+
export type UseCaseHookOptions<T, TUseCaseOptions extends object = object> = UnextendOptionTypes<TUseCaseOptions> & UseCaseHookOwnOptions<T, TUseCaseOptions>;
|
|
49
53
|
export interface ReducersHook {
|
|
50
54
|
<T extends ReducerMap, TUseCaseOptions extends object = object>(usecase: UseCase<T & SymbolSetTarget<NonEntitySymbolSet>, TUseCaseOptions>, options?: TUseCaseOptions, deps?: unknown[]): T;
|
|
51
55
|
}
|
|
@@ -826,6 +826,24 @@ var useDeepCompareUpdate = function useDeepCompareUpdate(callback, deps) {
|
|
|
826
826
|
});
|
|
827
827
|
(0, _globals.expect)(result.current[0].path).toBe('123/' + PATH_1);
|
|
828
828
|
});
|
|
829
|
+
(0, _globals.test)('Option functions: use `T` (not `S`) when `S extends T`', function () {
|
|
830
|
+
var testObjectUseCase = function testObjectUseCase() {
|
|
831
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
832
|
+
var objectReducers = (0, _usecases.objectUseCase)();
|
|
833
|
+
void options;
|
|
834
|
+
return _objectSpread({}, objectReducers);
|
|
835
|
+
};
|
|
836
|
+
(0, _react.renderHook)(function () {
|
|
837
|
+
(0, _.useUseCase)(defaultFile, testObjectUseCase, {
|
|
838
|
+
onUpdate: function onUpdate(data) {
|
|
839
|
+
void data;
|
|
840
|
+
return Promise.reject();
|
|
841
|
+
}
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
// 这个测试仅仅是为了确保类型不会报错,不验证实际逻辑
|
|
845
|
+
(0, _globals.expect)(1).toBe(1);
|
|
846
|
+
});
|
|
829
847
|
(0, _globals.test)('when `options` has changed, it should not trigger update', function () {
|
|
830
848
|
var onUpdate = _globals.jest.fn();
|
|
831
849
|
var onDeepUpdate = _globals.jest.fn();
|