microsoft / microsoft/TypeScript
Polymorphic `this` breaks when a module exports a variable and interface with the same name
オープン
まだ誰も着手していません。
Bug
Domain: This-Typing
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.3k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
Importing a variable that has a corresponding interface of the same name from a module causes unexpected behavior.
In the screenshot below, the function, doSomething, should return the type Model<number> due to polymorphic this; however, it returns Model<T>, which is unusable.
Here is an easy way to reproduce this behavior:
npm install -g @types/sequelize sequelize- Replace
node_modules/@types/sequelize/index.d.tswith the following
declare namespace sequelize {
interface Model<T> {
doSomething(arg: T): this;
}
}
declare var sequelize: { Model: sequelize.Model<any> };
export = sequelize;
- create a file with the following contents:
import { Model } from 'sequelize';
let a: Model<number> = null as any;
a.doSomething(5).doSomething();
Workaround:
Use import * as ... syntax and the names will resolve correctly.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供されたsequelize宣言を使い、名前付きインポート構文でModelをインポートして問題を再現します。polymorphic thisをチェックする際に、コンパイラーがエクスポートされた変数と同名のinterfaceをどのように解決するかを追跡します。完了条件は、例でModelが推論され、namespace-import workaroundを必要とせずにチェーン呼び出しが許可されることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100