microsoft / microsoft/TypeScript

Type a standard import with jsdoc only

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

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

Awaiting More Feedback Domain: JavaScript Domain: JSDoc Suggestion
主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

説明

🔍 Search Terms

ecmascript module import jsdoc

✅ Viability Checklist
⭐ Suggestion

Right now I can type an require call with

/**
 * @type {typeof import("./accounts").userAccount}
 */
var x = require("./accounts").userAccount;

from https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types

But when I my code uses an import statement
import { shortNameFromImport } from "textmodule";
I did not found a way to type that when the module resolution does found a hit.

@type in the line before can not be used because there is no let or const in this line.

/** @type {import('textmodule')} */
import { shortNameFromImport } from "textmodule";

And the normal way to type a variable with parenthesis can not be used because it is not valid JS code:

import { /** @type {import('textmodule')} */ (shortNameFromImport ) } from "textmodule";

Both variants without parenthesis do not work...

import { /** @type {import('textmodule')} */ shortNameFromImport } from "textmodule";
import { shortNameFromImport /** @type {import('textmodule')} */ } from "textmodule";
📃 Motivating Example

With typescript code I can do some magic with path in the tsconfig.json

"paths": {
  "textmodule": [ "./textmodule.ts" ]
},

But I wanted to have a JSDoc only solution.

💻 Use Cases

See above

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

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

はじめの一歩

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

調査の方向性

JSDocでサポートされている型のドキュメント、特にimport-typesセクションから始め、このissueにある名前付きインポートの例と、そのrequireの例を比較します。TypeScript checkerがJavaScriptのimport宣言に対するJSDocをどのように処理するかを追跡し、続いてサポートされるアノテーションのテストを定義して、JavaScriptの出力が変更されないことを確認します。

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

評価

技術スタック
javascript, typescript
領域
compilers
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

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

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