AMD TypeScript cannot resolve external module with custom require.config baseUrl

I have some problems with typescript + requirejs. I have two projects (main and one with unit tests). It looks like this:

solution with two projects
moduleA.ts:

export class A {
    constructor(someThing: string) {
        this.someThing = someThing;
    }
    someThing: string;
}
export var aInst = new A("hello from module A");


moduleB.ts:

import moduleA = require('moduleA');

export class B {
    private a: moduleA.A;

    constructor(a: moduleA.A) {
        this.a = a;
    }

    getSomeThing() {
        return this.a.someThing;
    }
}

export var bInst = new B(moduleA.aInst);


requireConfig.js:

require.config({
    baseUrl: "/app",
});


myTest.ts:

import moduleB = require('moduleB');

QUnit.test('my test', () => {
    QUnit.equal("hello from module A", moduleB.bInst.getSomeThing());
});


testRequreConfig.js:

require.config({
    baseUrl: "../Base/app",
});


index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    <link rel="stylesheet" href="Content/qunit.css" type="text/css" />
    <script type="text/javascript" src="Scripts/qunit.js"></script>

    <script src="Scripts/require.js"></script>
    <script src="test/testRequreConfig.js"></script>
</head>
<body>
    <h1 id="qunit-header">Unit Tests</h1>
    <h2 id="qunit-banner"></h2>
    <h2 id="qunit-userAgent"></h2>
    <ol id="qunit-tests"></ol>
    <div id="qunit-fixture">test markup, will be hidden</div>

    <script type="text/javascript">
        (function () {
            QUnit.config.autostart = false;
            require(['test/myTest.js'], QUnit.start);
        }());
    </script>
</body>
</html>

We cannot modify the Base project . We want to be able to use moduleB in the Test project (loading on demand on the moduleB line). What we have:
unable to load
TypeScript compiler cannot solve the external module (because it has no idea where to look for it). If we put

declare module "moduleB" {
 
    export  ...
}


*.d.ts - . typescript, 'declare' . - ? , require.config( ).

tsc.exe, require.config?

+4
2

tsc.exe, require.config?

. : def, typescript .

+3

, .

jquery.d.ts :

declare module "jquery" {
    export = $;
}
declare var jQuery: JQueryStatic;
declare var $: JQueryStatic;

, TypeScript import x=require(<module string>);.

, , , .

0

Source: https://habr.com/ru/post/1536791/


All Articles