microsoft / microsoft/TypeScript
Always verify import path
まだ誰も着手していません。
- 主要言語
- 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
- Importing images in TypeScript React - “Cannot find module”
- Webpack & Typescript image import
- Typescript image import
- TypeScript "Cannot find module './myFile..." for .scss, .less, images files, wasm...
- Importing SVG files as React Components in TypeScript
This approach fix the lint error, but disable TS intellisense.
Example
Folder structure
app
|
├ img
| └─ top-view.svg
|
└─index.ts
index.ts

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).
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず関連する issue #40333 とこのレポートの例を読み、その後、TS/JS 以外のファイルに対する TypeScript の import-path 解決動作を調査します。提案された missing-file 診断の動作が定義・実装され、宣言された non-code モジュールのサポートが失われていなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100