Description
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
2.5.2
Code
/bundles
- app.js
- app.d.ts
- common.js
- common.d.ts
- core.js
- core.d.ts
/app
- main.ts
- tsconfig.ts
/src/common
- index.ts
- file1.ts
- tsconfig.json
/src/core
- index.ts
- file1.ts
- tsconfig.json
//app/main.ts
import { resource } from '@bundles/core'
import { somethingElse } from '@bundles/common'
//common/index.ts
export * from './file1.ts'
//core/index.ts
export * from './file1.ts'
//app/tsconfig.json
...
"target": "es5",
"module": "system",
"rootDir": ".",
"outFile": "../bundles/app.js",
"declarations": true,
"paths": {
"@bundles/*": ["../bundles/*"]
}
...
//common/tsconfig.json
...
"target": "es5",
"module": "system",
"rootDir": ".",
"outFile": "../bundles/common.js",
"declarations": true,
"paths": {
"@bundles/*": ["../bundles/*"]
}
...
//core/tsconfig.json
...
"target": "es5",
"module": "system",
"rootDir": ".",
"outFile": "../bundles/core.js",
"declarations": true
"paths": {
"@bundles/*": ["../bundles/*"]
}
// bundles/common.d.ts
declare module "index" {
export * from 'file1'
}
// bundles/core.d.ts
declare module "index" {
export * from 'file1'
}
...
Expected behavior:
TSC to correctly resolve the import statements within app/main.ts
against the configured --paths
, applying the same logical resolution strategy that lets it resolve barrels.
(note: I've had to escape the [@] symbols for some reason at the start of these lines).
"[@]bundles/common" => '../bundles/common.d.ts' => '../bundles/common.d.ts [declared module "index"]' (OK)
"[@]bundles/core" => '../bundles/core.d.ts' => '../bundles/core.d.ts [declared module "index"]' (OK)
"[@]bundles/*" => '../bundles/*.d.ts => "[declared module *]" => "[declared module index]" => "../bundles/*/index.d.ts" => "[declared module *]" => "[declared module index]"
Actual behavior:
It appears the path part of the import statement is currently expected to be included in the declared module name.
"[@]bundles/common" => '../bundles/common.d.ts' => '../bundles/common.d.ts [declared module "@bundles/common"]' (FAIL)
Even if I name index.ts
to common.ts
for example, this will still fail because the resolution logic is expecting the "@bundles"
path token to be in the declared module name.
I can coerce the expected behavior by creating a "@bundles" folder inside my module - but the whole point is that the "--paths" option shouldn't be married to the module structure.
/src/common
- @bundles/
-- common.ts
//src/common/@bundles/common.ts
export * from '../index'
//bundles/common.d.ts
declare module "index" {
exports "file1
}
declare module "@bundles/common" {
exports "index"
}