microsoft / microsoft/TypeScript
[Regression] Circular reference error when passing a class expression with non-primitive static properties to a generic function
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
🔎 Search Terms
class expression static type
🕗 Version & Regression Information
- This changed between versions 4.0.5 and 4.1.5
⏯ Playground Link
💻 Code
declare function returnInput<T>(input: T): T;
const a = returnInput(class A {
static foo = {}
// ^?
})
🙁 Actual behavior
A.foo: any
Error: 'foo' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.(7022)
And also note that this bug only happens when the type of foo is not a primitive type.
🙂 Expected behavior
A.foo: {}, as it works in 4.0.5
Additional information about the issue
To define a React class component, it is a common practice to include its "sub-components" as private static properties. I also use a "observer" function to make the state change auto observed. So the real-world code may look like:
import { observer } from 'mobx-react';
import { styled } from 'styled-components';
@observer
class ListView extends React.Component {
// render method here...
private static readonly Item = observer(class Item extends React.Component {
private static readonly Header = styled.h4` // <- Cannot infer the type of Header
// CSS style here...
`;
})
}
A workaround is to use static block to initialize the static property but it's cumbersome:
const a = returnInput(class A {
static foo
// ^? OK
static { this.foo = {}; }
})
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされた TypeScript Playground から始め、ジェネリック関数とクラス式の例を使って、バージョン 4.0.5 と 4.1.5 の間のリグレッションを比較してください。非プリミティブな静的プロパティがなぜ any と推論されるのかを調査し、ドキュメント化された workaround の動作を維持したまま、例がエラー 7022 なしで A.foo を {} と報告すれば Issue は完了としてください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100