microsoft / microsoft/TypeScript
resolve declaration extension assets as paths and directing users to the correct implementation
还没有人认领这个 Issue。
- 主要语言
- Go
- 星标
- 111k
- 派生
- 14.4k
- 平均合并
- 1 天 19 小时
- 30 天内合并 PR
- 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:
- https://stackoverflow.com/questions/76597629/how-to-write-path-resolutions-for-assets-that-require-declarations-and-open-the
- https://stackoverflow.com/questions/72084536/vscode-svg-declarations-file-resolved-instead-svg-file-path-with-react-native-an
📃 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
- 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.
- 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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 TypeScript 编译器入口点 tsc,以及现有的声明文件和 tsconfig 路径解析行为。该 issue 没有列出任何仓库文件或测试;要完成它,需要为 asset 扩展名、解析目标以及缺失 asset 的诊断定义设计并进行验证。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript
- 领域
- compilers
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 20/100