类型推断在TypeScript中丢失了内部级别类型

xbt*_*tsw 2 typescript

在下面的代码示例中,我想不通为什么FinalType{ test: { test_inner: any } }.我不知道any它来自哪里(并且string丢失了).同时,test有正确的回归类型{ test_inner: string }

interface IAction {
    type: string;
}

type Reducer<S> = (state: S, action: IAction) => S

function combineReducers<S>(reducers: { [K in keyof S]: Reducer<S[K]> }): Reducer<S> {
    const dummy = {} as S;
    return () => dummy;
}

const test_inner = (test: string, action: IAction) => {
    return 'dummy';
}
const test = combineReducers({
    test_inner
});

const test_outer = combineReducers({
    test
});

type FinalType = ReturnType<typeof test_outer>;
Run Code Online (Sandbox Code Playgroud)

我正在键入我的redux应用程序.但我认为问题不是针对redux的.我很清楚,@types/redux但我不想使用它.

Rya*_*ugh 5

这是TypeScript如何向您显示类型的错误 - 记录https://github.com/Microsoft/TypeScript/issues/23897

真正的类型FinalType实际上是正确的; 这只是一个显示错误.