簡體   English   中英

TypeScript中的類型推斷丟失了內部級別類型

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM