microsoft / microsoft/TypeScript

resolve declaration extension assets as paths and directing users to the correct implementation

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

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

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

説明

Suggestion

Resolve string paths with nodeJS for declaration assets. And allow the resolution implementation to be directed to instead of the declaration file.

🔍 Search Terms

path resolution, custom declarations, assets, svg, png, jpg, webp, wav, mp4 etc.

✅ Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Add the ability to resolve custom declarations based on path within typescript directly.

  • This would make it much easier to fix issues with assets that are considered typescript strings.
  • Would not require third party plugins such as https://www.npmjs.com/package/eslint-plugin-validate-declared-imports
  • It should support tsconfig paths.
  • Validation should be done when running tsc. It should output an error when a string that is flagged as an asset is not resolvable.

Add the ability to go directly to the file now that string paths are being resolved as potential files

Add the ability to define which asset extensions in declarations are resolvable

  • would allow declarations to be able to say if the declaration is an asset and if it can be resolved.
  • Some assets like .mp4 should not be opened in most IDEs. But assets like svgs (and other files) would benefit from having this option.

This would prevent declaration path matching from causing runtime problems due to the assets missing and not being validated with tsc.

Related issues on Stack Overflow:

📃 Motivating Example

Adding this feature will prevent runtime issues with missing assets due to typos or changes in a codebase. This allows developers to directly import assets that are considered strings in typescript and retain file path validation for those new assets.

Adding this feature will also speed up development process when assets need to be tweaked. Example SVGs can be mutated in the VSCode IDE but clicking on an imported svg will redirect the user to a declaration instead of the asset implementation. Directing the user to the asset implementation would speedup things for everyone.

💻 Use Cases

  1. Prevent runtime issues related to assets path not matching and/or having typos in a path and typescript ignoring those typos due to the path being considered a pure string.
  2. Stabilizes the code even for external solutions that use imports.

I want to use this feature for any project that requires a asset to be declared as a string asset in a declaration file and resolve the asset extension using typescript directly instead of third party linting plugins such as eslint.

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

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

はじめの一歩

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

調査の方向性

まず TypeScript コンパイラーのエントリーポイント tsc と、宣言ファイルおよび tsconfig の既存のパス解決動作を読みます。この issue ではリポジトリ内のファイルやテストが指定されていないため、完了にはアセット拡張子、解決対象、アセットが見つからない場合の診断について、設計の定義と検証が必要です。

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

評価

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

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

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