typescript with require-js how to avoid specifing full path to file in require()

174 views Asked by At

I have 2 files:

baseVM.ts(in bases folder):

class BaseVM {
    a: string;
    data: any;
    constructor() {
        this.data = {};
    }
    getData() {
        return "Hi bros";
    }
}
export = BaseVM;

Example.ts(in someFolder)

import BaseVM = require("baseVM");
class Example extends BaseVM {
    controlModule: KnockoutObservable<Module>;
    data: PolicyOrderDTO;
    constructor() {
        super();
    }
}
export = Example;

and I have also configured require-config(require-config.ts):

requirejs.config({
    baseUrl: "Scripts/app",
    paths: {
        "baseModel": "/bases/baseVM",
        "Example":"/someFolder/Example"
    }
});

require(["Example"], (Example)=>{
   var example = new Example();
   example.getData();
});

But it dont build and show the error in Example.ts in line import BaseVM = require("baseVM");. It says that he cant find file, but to write always the full path is a bit annoying. Thanks in advance.

1

There are 1 answers

1
basarat On

but to write always the full path is a bit annoying

Sadly you need to specify full paths at the moment. IDEs can make it easier : https://github.com/TypeStrong/atom-typescript#relative-paths

Also there is typescript issue tracking this : https://github.com/Microsoft/TypeScript/issues/2338