microsoft / microsoft/TypeScript
Undocumented node_modules/@types fallback strategy for classic module resolution
まだ誰も着手していません。
- 主要言語
- Go
- スター
- 111k
- フォーク
- 14.4k
- 平均マージ
- 1日 19時間
- マージ済み PR(30日)
- 117
説明
I'm using TypeScript 2.7.2 with MSBuild 15.9.21.664
A fallback was added to classic module resolution to resolve modules using node_modules/@types in this PR https://github.com/Microsoft/TypeScript/pull/11147
Going purely from the Module Resolution section of the handbook, I would have expected this behaviour only when using node module resolution.
This is undocumented behavior is an issue because the fallback will override any ambient module declarations in the resolution process.
To give some context, I have a ASP.NET MVC project that uses MSBuild to compile TypeScript. This project takes advantage of some TypeScript files in a separate NPM project located up a few directions on in the File system by using the following csproj syntax:
<TypeScriptCompile Include="..\..\external-typescript-project\src\Cat.ts">
<Link>Scripts\app\Cat.ts</Link>
</TypeScriptCompile>
When MSBuild shells out to tsc it does so like tsc "..\..\external-project\src\Cat.ts".
So far so good, except if both projects share the same TypeScript definition dependency i.e. if both the MVC project and external NPM project have a TypeScript definition for jQuery, the "....\external-typescript-project\node_modules@types\jquery.index.d.ts" is used in preference to the MVC project's ambient jQuery module declaration.
If I manually delete the "....\external-typescript-files\node_modules@types\jquery.index.d.ts" file the MVC project gets the correct ambient module declaration.
In an ideal world I'd disable MSBuild triggering the compilation using <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked> and manage TypeScript definition dependencies using NPM with module resolution "node", but the entire project relies on ambient module declaration files in a custom ".\typescript-definitions" folder which gets passed to the TypeScript compiler i.e. tsc "..\..\external-project\src\Cat.ts" "typescript-definitions\jquery\index.d.ts", so it would be a tricky migration.
My understanding is path mapping would solve the issue, but unfortunately this isn't supported by MSBuild. I would like the ability to opt-out of falling back to node_modules/@typings when using classic module resolution, or at the very minimum this behaviour could be documented.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
TypeScript ハンドブックの「Module Resolution」セクションと PR #11147 から始め、次に、そこに記載されている動作と、ここで説明されている classic-resolution のフォールバックを比較します。node_modules/@types のフォールバックが正確に文書化されるか、issue が特定のオプトアウト要件に絞り込まれれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- compilers
- issue の種類
- ドキュメント
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100