2

I'm using an existing js library that uses AMD modules in my typescript code. I want to use a Javascript class as the base for my Typescript class. This is what I'm trying to do:

famous.js

define('famous/core/View',['require','exports','module'],function(require, exports, module) {

    function View() {
        ...
    }

    ...

    module.exports = View;
});

View.d.ts

declare module "famous/core/View" {

}

AppView.ts

import View = require('famous/core/View');

class AppView extends View {

}

export = AppView;

But it says "Cannot find name 'View'". I suppose it's logical it doesn't work since a module is not a class, but I don't know another way.

2 Answers 2

1

You need to define a class and use export = in View.d.ts. For example:

declare module "famous/core/View" {
   class View {
      // TODO define members of View
   }
   export = View;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome that works. I expected that when I declare a class in the module I would need to use it like this: import View = require('famous/core/View'); var view = new View.View(); . But it doesnt, it works perfectly, thanks!
0

On further analysis it seems like purely a require configuration problem. It shouldn't have anything to do with class vs module. Are you sure your paths are correct and you have a config.ts require configuration file?

1 Comment

The js code is part of the library I'm using. That's beyond my control

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.