Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am using typescript in AMD mode (using requirejs).

Let's say I want to add a function to String, at the moment I do:

Extensions/String.ts

interface String {
    startsWith(str: string): boolean;
}

define(() => {
    String.prototype.startsWith = function (str)
    {
        return (this.match("^" + str) == str);
    };
});

This works and generate the right .js file and I am able to use in non-typescript requirejs modules.

How do I "import" this requirejs module in a typescript class?

In the file of the class that wants to use the new functions, this doesn't work:

types/SampleClass.ts

import ExtensionsString = require("Extensions/String");

I get this error:

"unable to resolve external module '"Extensions/String"'

How can I make typescript add "Extensions/String" to the list of dependencies

types/SampleClass.js

define("SampleClass", ["Extensions/String"], function(/* no need to have parameter */){

...

});

Thanks for your help!

share|improve this question
    
declare module "Extensions/String" { ... } –  Stephen Chung Jun 7 '14 at 10:13
    
Your own answer will work but your String.ts is a hybrid between an internal (TS) and external (AMD) module. Which one would you like String.ts to be? –  coudy Jun 7 '14 at 10:22
    
How would it look like if I use an internal module (non hybrid)? –  Aymeric Gaurat-Apelli Jun 7 '14 at 10:32

1 Answer 1

up vote 1 down vote accepted

I found the solution, I just need to add the following line in the SampleClass.ts file instead of using import:

/// <amd-dependency path="Extensions/String" />
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.