microsoft / microsoft/TypeScript
Support either type asserting `self` in classes, or properly ignoring workaround
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 132
説明
I currently have a scenario very similar to https://github.com/microsoft/TypeScript/issues/2000#issuecomment-546929745. While it would be fixed it TS natively supported overriding class methods (see that issue), I followed the outline of the linked comment, but am running into a small issue. This is not a huge blocker but rather a nice-to have to get proper type completion for my scenario.
export class WritableObjStream<T> extends (stream.Writable as any) {
writableObjectMode: true
write(object: T, cb?: (error: Error | null | undefined) => void): boolean {
return super.write(...more details)
}
}
Because we type assert the base class to any, TS has no knowledge of the superclass. I tried a few solutions, with errors included below:
(super as any).write() // 'super' must be followed by an argument list or member access.
let s: stream.Writable = undefined;
// @ts-ignore
s = super // Identifier expected.
return s.write() // 'super' must be followed by an argument list or member access, Expected 1-3 arguments, but got 0.
Luckily, it autocomplete is picking up on the proper type of s.write() now and giving me an argument error.
Also, from what I can gather super is treated as a keyword not an identifier, which results in the error above.
This may not be the most common of errors, but there may be a few scenarios/other use cases. I tried writing a few examples up but none made real-world sense besides this use-case of a workaround for overriding methods.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Issue のクラス例と、回避策を説明しているリンク先の TypeScript issue/comment から始めます。このシナリオで TypeScript が super をどのようにパースし、型チェックするのかを調査し、そのうえで self の型アサーションをサポートすべきか、それとも回避策を明示的に拒否すべきかを判断します。示された例をカバーするテストによって、選択した動作が文書化されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100