[英]Type inference lost inner level types in 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>;
我正在輸入redux應用程序。 但是我認為問題並不特定於redux。 我對@types/redux
很清楚,但我不想使用它。
這是TypeScript如何向您顯示類型的錯誤-登錄https://github.com/Microsoft/TypeScript/issues/23897
FinalType
的實際類型實際上是正確的; 這只是一個顯示錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.