microsoft / microsoft/TypeScript

Undocumented node_modules/@types fallback strategy for classic module resolution

Abierto
#29,443 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con la sección «Module Resolution» del manual de TypeScript y el PR #11147; después, compara su comportamiento documentado con el fallback de classic-resolution descrito aquí. Se considera terminado cuando el fallback de node_modules/@types esté documentado con precisión, o cuando el issue se haya acotado a un requisito específico para excluirlo.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Documentación
Dificultad
3/5
Tiempo estimado
1-2 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.