Search code examples
javascripttypescriptamd

Typescript, require module as class


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.


Solution

  • 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;
    }