microsoft / microsoft/TypeScript
Property 'X' does not exist on type Y
オープン
まだ誰も着手していません。
Bug
Domain: This-Typing
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "does not exist on type"
⏯ Playground Link
Playground link with relevant code
💻 Code
type Listener = {
callback(): boolean;
};
const fn = <T extends Listener>(listener: T) => { };
// this works
fn({
context: new Map<string, number>(),
callback() {
const num = this.context.get('number') ?? 0;
if (num > 0) return true;
else return false;
},
});
// this does not
fn({
context: new Map<string, number>(),
callback() {
const num = this.context.get('number') ?? 0; // Property 'context' does not exist on type 'Listener'.(2339)
return num > 0;
},
});
🙁 Actual behavior
It is giving a compilation error as soon as I change the return variable.
🙂 Expected behavior
Should not give compilation errors.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground の例から始め、fn への 2 つの呼び出しを比較します。コールバックの this 値に対するコンテキスト型付けとジェネリック推論に注目してください。2 つ目の例が、報告されている Property 'context' エラーなしでコンパイルされ、1 つ目の例の動作を維持できれば、Issue は完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100