Closed AbraaoAlves closed 10 years ago
Hi @AbraaoAlves,
The code snippet: import main = require('main');
when compiled will be changed to: var main = require('main');
. With this, node.js will looking for a module installed via npm. In this case, you will need to put the relative path to main.ts
file: var main = require('../../src/main');
Let's change the main.ts
file to:
/// <reference path="_reference.ts" />
export module main {
export var teste = function teste() {
return 'testando';
};
}
And the file mainSpec.ts
to:
/// <reference path="../../typings/tsd.d.ts" />
/// <reference path="../../src/_reference.ts" />
import main = require('../../src/main');
describe('a test example', () => {
it('it example', () => {
expect(main.main.teste()).toEqual('testando');
});
});
Now you can execute the tests.
To avoid the
main.main.teste()
we can change themain.ts
file to:
/// <reference path="_reference.ts" />
module main {
export var teste = function teste() {
return 'testando';
};
}
export = main;
Let me know if this working good to you. I'll improve the README with more instructions. I need more time to do it :)
Ok, this work ! But what is wrong with Global / External-agnostic Libraries declaration ? This should be independent of module use ?
You will use external modules if you are building a type declaration to an existent npm module (if using commonjs/node.js) or if you are using an AMD module that has been configured with a specific name.
Example:
If you are using node.js and have the underscore
npm module installed you can use the following type declaration to load the underscore
module:
declare module "underscore" {
//...
}
And load this with:
import _ = require("underscore");
If you are using an AMD structure like RequireJS, you will use the same type declaration above.
The external module exists to supply the CommonJS and AMD specifications. Take a look at this post: https://typescript.codeplex.com/wikipage?title=Modules%20in%20TypeScript looking for "Going External" topic.
Ô cabra machu arretado ! Tu merece um caminhão carregado de coco babão, machu véi.
translate cearence -> english:
Thanks a lot for your help.
kkkkkkkkkkkkkk... vlw brother! :)
@AbraaoAlves Just to you know, I updated the README with some instructions and changed the exampleSpec.ts to load the main module ;)
I put a new file, 'mainSpec.ts', inside folder 'specs' with this content:
Follow directives of typescript documentation about Global / External-agnostic Libraries:
When I run command line, I get:
Exception loading : c:\Users\abraaoalves...\ts-boilerplate-master-nodejs\test\specs\mainSpec.js { [Error: Cannot find module 'main'] code: 'MODULE_NOT_FOUND' }