microsoft / microsoft/TypeScript
Check JS doesn't narrow types properly
オープン
まだ誰も着手していません。
Needs Investigation
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
TypeScript Version: 3.7.x-dev.201xxxxx
Search Terms:
Code
import { useReducer } from 'react';
/**
* @template {{ type: string; payload?: any; }} Action
* @template {object} State
* @template {{ past: State[]; present: State; future: State[]; }} UndoState
* @template {{ type: 'UNDO'; } | { type: 'REDO'; }} UndoAction
* @param {{ (state: State, action: Action): State; }} reducer
* @param {State} initialState
*/
export function useUndoReducer(reducer, initialState) {
/**
* @param {UndoState} state
* @param {UndoAction | Action} action
*/
const undoReducer = (state, action) => {
switch (action.type) {
case 'UNDO': {
const [newPresent, ...newPast] = state.past;
return {
past: newPast,
present: newPresent,
future: [state.present, ...state.future],
};
}
case 'REDO': {
const [newPresent, ...newFuture] = state.future;
return {
past: [state.present, ...state.past],
present: newPresent,
future: newFuture,
};
}
default:
return {
past: [state.present, ...state.past],
// @ts-ignore
present: reducer(state.present, action),
future: [],
};
}
};
return useReducer(undoReducer, {
past: [],
present: initialState,
future: [],
});
}
Expected behavior:
not having to use a @ts-ignore
Actual behavior:
had to use @ts-ignore
Playground Link:
Related Issues:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
報告されたバージョン 3.7.x-dev を使用して、リンクされた TypeScript Playground の再現例から始め、action.type に対する switch を通じて JSDoc 型がどのように絞り込まれるかを調べてください。報告された reducer 呼び出しを期待される型と比較してください。指定された reducer 型と action 型を維持したまま、例で @ts-ignore が不要になれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, react, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100