I have the following project structure:
- /
- tsconfig.json
- tsconfig-base.json
- /src
- types.ts
- tsconfig.json
- /test
- myTest.ts
- tsconfig.json
- /dist
/tsconfig.json
is a solution, it references /src/tsconfig.json
and /test/tsconfig.json
.
/src/tsconfig.json
and /test/tsconfig.json
both inherit from /tsconfig-base.json
which contains project-wide compilerOptions
.
/test/tsconfig.json
references /src/tsconfig.json
to get access to the types declared in /src/types.ts
. These types are visible within /src
but not from /test
, as expected. What am I doing wrong?
/tsconfig.json
{
"files": [],
"include": [],
"references": [
{ "path": "src" },
{ "path": "test" }
]
}
/tsconfig-base.json
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"outDir": "dist",
"rootDir": ".",
"composite": true,
"declaration": true,
"sourceMap": true,
"declarationMap": true
}
}
/src/tsconfig.json
{
"extends": "../tsconfig-base",
"include": [
"./*",
"./**/*"
]
}
/test/tsconfig.json
{
"extends": "../tsconfig-base",
"references": [
{ "path": "../src" }
],
"include": [
"./*",
"./**/*"
]
}
/src/types.ts
interface Array<T> {
myTestMethod(): void
}
/test/myTest.ts
const arr: Array<string> = new Array<string>();
arr.prototype.myTestMethod; // Should be undefined; instead throws "property myTestMethod does not exist [...]"
Update 1:
If /test/tsconfig.json
is directly made aware of the /src/types.ts
script (not a module), it seems to work:
{
"extends": "../tsconfig-base",
"references": [
{ "path": "../src" }
],
"include": [
"./*",
"./**/*",
"../src/types.ts"
]
}
This solution however, in my opinion, is quite dirty. By /test
referencing /src
, shouldn't the /src/types.ts
script be visible and run automatically? Isn't it the intended behaviour?