microsoft / microsoft/TypeScript
JavaScript class property becomes `any` without warning when used in a function that is assigned to itself
オープン
まだ誰も着手していません。
Awaiting More Feedback
Suggestion
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
jsdoc class null any
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
any
⏯ Playground Link
💻 Code
export class Foo {
/**
* @param {number?} maybeNum
*/
constructor(maybeNum) {
this.maybeNum = null;
this.setMaybeNum();
}
setMaybeNum() {
this.maybeNum = Math.max(this.maybeNum);
}
/**
* @param {string} str
*/
takesString(str) {}
foo() {
this.takesString(this.maybeNum);
// ^^^^^^^^^^^^^---- no error, maybeNum is any
}
}
🙁 Actual behavior
this.maybeNum is any
🙂 Expected behavior
this.maybeNum is number | null or (since noImplicitAny is set) an error is emitted warning the user that this.maybeNum is any.
Additional information about the issue
It seems like the core issue here is this line:
this.maybeNum = Math.max(this.maybeNum);
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の例と、JavaScript クラス内の代入 this.maybeNum = Math.max(this.maybeNum) から始めます。その代入が後続の呼び出し takesString(this.maybeNum) にどのような影響を与えるかを追跡し、その後、期待される number | null 型または noImplicitAny 診断に対して修正を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- javascript, typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 35/100