I have a large project that is mostly JavaScript. I would like to add some TypeScript. Things are mostly working fine. However, I have a large number of paths aliases and packages. So, when I
import foo = require('foo');
This will, in runtime, rely on a path configuration, say
require.config({
paths: {
foo: 'foobar/baz/js/quux'
}
});
So, predictably, the compiler gives me:
error TS2307: Cannot find module 'foo'
Is there any way that I could load in my requirejs configuration so that the compiler will be happy? Alternatively, is there a way that I suppress/ignore the error? The output JavaScript looks and runs fine. If I suppress the error, I wonder what I would be losing ... Can I specify where to find all my modules?
You can declare your own module in a definition file:
// my-modules.d.ts
declare module "foo" {
}
This way, gulp-typescript will not complain as long as the my-modules.d.ts
file compiles with the rest.
is there any way that I could load in my requirejs configuration so that the compiler will be happy?
Not yet. Look out for https://github.com/Microsoft/TypeScript/issues/5039
Alternatively, is there a way that I suppress/ignore the error?
Only if you want to be completely unsafe aka any
:
var foo:any = require('foo');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.