Cannot import properties from module.exports as types in JSDoc

オープン
#29,485 コメント 3 件 リアクション 13 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
javascript, typescript
領域
compilers

調査の方向性

まず、TypeScript の JSDoc チェックを有効にして a.js と b.js の例を実行します。import('./a') の型と module.exports の処理を確認し、その後、単一エクスポートの動作を変更せずに、A プロパティがコンストラクターのパラメーター型として認識されることを検証します。この再現で報告されたエラーがなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Bug Domain: JavaScript

TypeScript Version: 3.3.0-dev.20190118

Search Terms: jsdoc import module.exports has no exported member

Code

a.js

class A {}

module.exports = {A}

b.js

// @ts-check
class B {
	// In the JSDoc below, VSCode intellisense does not recognize parameter a as type A.
    // Instead it shows the error:
    //   Namespace '".../a".export=' has no exported member 'A'

	/**
	 * @param {import('./a').A} a
	 */
	constructor (a) {
		this.a = a
	}
}

Expected behavior
Parameter a of the constructor should be recognized as type A, which is accessible via the A property of module.exports from a.js.

Actual behavior
Intellisense reports the error: Namespace '".../a".export=' has no exported member 'A'.

Notes
@param {import('./a')} a does not give an error, but it resolves to type {A: typeof A} instead of A.

If a.js is modified with module.exports = A, then import('./a') resolves to A, however this restricts a.js to only exporting one type.

主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。