microsoft / microsoft/TypeScript
React and defaultProps cant pass correct props to inner function
オープン
まだ誰も着手していません。
Needs Proposal
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
TypeScript Version: 2.4.0
Code
import * as React from 'react';
interface CircleProps {
percent?: number
}
export default class Circle extends React.Component<CircleProps> {
public static defaultProps: Partial<CircleProps> = {
percent: 100
}
calculateDashArray(percent: number): string {
return `${percent}`
}
render() {
const strokeDasharray = this.calculateDashArray(this.props.percent)
return (
<div>{strokeDasharray}</div>
)
}
}
Expected behavior:
this.calculateDashArray should correct accept value of defalutProps
Actual behavior:
Argument of type 'number | undefined' is not assignable to parameter of type 'number'.
Type 'undefined' is not assignable to type 'number'.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue にある TypeScript 2.4 の例を再現し、React.Component の props と静的な defaultProps がどのように表現されているかを調べます。render 内の this.props.percent の想定される型を特定し、その後、示されているエラーと default-prop の動作についてのコンパイラテストを追加または更新します。例がデフォルトで指定された値を受け入れ、無関係な prop のチェックを弱めないことが完了の条件です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react, typescript
- 領域
- compilers, frontend
- issue の種類
- バグ
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100