Description
TypeScript Version: 2.1.1 / nightly (2.2.0-dev.201xxxxx)
2.1.5
Code
app.ts
import Foo from '/common/Foo' console.log(new Foo)
tsconfig.json
{ "compilerOptions": { "paths": { "/common/*": ["../../common/*"] } } }
Filesystem:
website/ common/ Foo.js somewhere/ project/ tsconfig.js app.js
Expected behavior:
tsc
should be able to recognize that when it sees a dependency like /common/Foo
it should look for website/common/Foo.js
in the filesystem.
Actual behavior:
It can't.
** More details **
I can get the following to successfully resolve files, by simply removing the leading slashes:
app.ts
import Foo from 'common/Foo' console.log(new Foo)
tsconfig.json
{ "compilerOptions": { "paths": { "common/*": ["../../common/*"] } } }
Filesystem:
website/ common/ Foo.js somewhere/ project/ tsconfig.js app.js
In this case, however, the output module contains something like
output.js
define(['common/Foo'], function(Foo) { /*...*/ })
But this is problematic, because if baseUrl
in RequireJS config is set,
require.config({baseUrl: '/some/place'})
then RequireJS will look for the module at example.com/some/place/common/Foo.js
which doesn't exist. I need it to look for the dependency at example.com/common/Foo.js
, f.e. TypeScript would output the following including the leading slash:
output.js
define(['/common/Foo'], function(Foo) { /*...*/ })
It would be great if TypeScript could support this case, then the output can still have an absolute path and work as expected.
Unfortunately, RequireJS doesn't support map configs like the following:
require.config({
baseUrl: '/some/place',
map: {
common: '../../common'
}
})
I think solving this in TypeScript is the best options because then it can be taken advantage of in other environments besides RequireJS.