Simon H
Simon H

Reputation: 21037

Migrating (Mongoose) code to Typescript

I'm trying to migrate more of my backend code to Typescript as I love having type checking, and the marketing always suggests you can do as much or as little as you like in typescript. But it remains really hard to set it up, even in VS Code which is supposed to make it easy.

Here is a new module I am creating. The reference path is correct, but nothing after that is working. I can't for example, use the Model interface; import .. = require can't find the .js file; the mongoose name space is not available for my interface definition;...

What should I do to make some progress?

///<reference path="../../../typings/mongoose/mongoose.d.ts" />

// var Resto : Model    = require('./resto.model');
import Resto = require('./resto.model');  // a .js file

interface IResto extends mongoose.Document {
    "qname"          : string;
    "rname"          : string;
    "similar"       : string[];
}

Resto.find({})

Upvotes: 1

Views: 627

Answers (2)

Simon H
Simon H

Reputation: 21037

This page turned out to be the most helpful

Upvotes: 0

basarat
basarat

Reputation: 276303

import .. = require can't find the .js file;

import will only find the ts file. Change the extension to .ts

More tips : https://basarat.gitbooks.io/typescript/content/docs/types/migrating.html

Upvotes: 1

Related Questions