microsoft / microsoft/TypeScript

Always verify import path

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

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

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

説明

In many projects is necessary work with files which isn't a TS/JS file. Some common ones are png, jpg, svg, but when importing this files we get Cannot find module or its corresponding type declarations. error.

Searching how to fix that, we come across many discussions suggesting using the global module declaration, such as:

declare module '*.svg' {
  const content: string
  export default content
}

Links

This approach fix the lint error, but disable TS intellisense.

Example

Folder structure

app
 |
 ├ img
 |  └─ top-view.svg
 |
 └─index.ts

index.ts
68747470733a2f2f692e737461636b2e696d6775722e636f6d2f6d36494a592e706e67

No errors, but the correct path is ../img/top-view.svg

Here is the related issue #40333


Suggestion

Compiler could still returning missing type declarations for not TS/JS files. But always check if import path results in a file and return an error if not (even if file is not an TS/JS).

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

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

はじめの一歩

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

調査の方向性

まず関連する issue #40333 とこのレポートの例を読み、その後、TS/JS 以外のファイルに対する TypeScript の import-path 解決動作を調査します。提案された missing-file 診断の動作が定義・実装され、宣言された non-code モジュールのサポートが失われていなければ完了です。

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

評価

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

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

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