Description
TypeScript Version: 3.4.0-dev.201xxxxx
Search Terms:
types conflict
modules conflict ts(2742)
duplicate modules
module versions conflict
monorepo modules conflict
Code
index.ts (main project)
import { moduleB } from 'ts-issue-module-b';
// import { SomeInterface } from 'ts-typelib-example'; // this line makes no sense
const valueB = moduleB(3); // <---- error ts(2742)
export {
valueB
}
ts-module-b (linked package module)
import { SomeInterface } from 'ts-typelib-example';
import { moduleA } from 'ts-issue-module-a';
export const moduleB = (age: number): SomeInterface => {
const data = moduleA(age.toString())
const ageString = data.age;
const value: SomeInterface = {
age: parseInt(ageString, 10)
}
return value;
}
ts-module-a (module-b dependency)
import { SomeInterface } from 'ts-typelib-example';
export const moduleA = (age: string): SomeInterface => {
const value: SomeInterface = {
age
};
return value;
}
For SomeInterface
it exists in 2 versions: (1.0.0) where age is a string and (2.0.0) where age is a number. (breaking change version.
Expected behavior:
The expected behaviour is that the returned interface by moduleB should be the 2.0.0 version interface (as expected from node_modules resolution first level). Instead, VSCode displays an error telling to import SomeInterface to resolve the conflict.
Actual behavior:
TypeScript cannot resolve the type returned by the moduleB function creating undesirable errors in dependencies. (This error could exist in thousands of dependencies due to developers cant update 2nd level dependencies from third party modules).
Playground Link:
https://github.com/imt-jaime/ts-monorepo-issue-example
Related Issues:
** Repository Structure **
- node_modules
- module-b (linked)
- src
- index.js
- packages
- module-b (linked globally)
- node_modules
- ts-typelib-example (v2.0.0)
- module-a
- node_modules
- ts-typelib-example (v1.0.0)
- src
- package.json
- node_modules
- src
- package.json
- node_modules
- ts-typelib-example
- node_modules
- src
- package.json
- module-b (linked globally)
- package.json
More information can be found in the repository (README.md)