2

What must the module code (writen in typescript) look like to be able to use it like this:

/// <reference path="./onoff.ts" />

//import * as onoff from "./onoff";
var onoff = require("./onoff");

var app = onoff();

var computers: Onoff.Computer[] = [];
app.start(computers);

I was sure it must be this, but it does not work:

import * as express from "express";
export module Onoff {    

    export class Computer {

    }

    export class OnoffApp {


        start(computers:Computer[], port:number = 3489) {
           ...
        }
    }

    export default function() {
        return new OnoffApp();
    }
}

Typescript complains:

service/example.ts(5,11): error TS2349: Cannot invoke an expression whose type lacks a call signature.
service/example.ts(7,16): error TS2503: Cannot find namespace 'Onoff'.
service/example.ts(8,21): error TS2503: Cannot find namespace 'Onoff'.
typings/express/express.d.ts(14,1): error TS6053: File 'typings/serve-static/serve-static.d.ts' not found.
typings/express/express.d.ts(28,34): error TS2307: Cannot find module 'serve-static'.

thank you very much! I have no Idea what I've done wrong...

1 Answer 1

1
  1. Judging from the error description, moving the import outside of your module should fix your problem:

    import * as express from "express";
    export module Onoff {
        ...
    }
    
  2. You import your module as onoff but are trying to use Onoff

    var onoff = require("./onoff");
        ^
    var computers: Onoff.Computer[] = [];
                   ^
    
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, that fixed the error in onoff.ts but not the other errors. I modified the question accordingly.
you import your module as onoff but are trying to use Onoff
If i do that it says error TS2305: Module '"service/onoff"' has no exported member 'Computer'..
export default function() { return new OnoffApp(); } var onoff = require(...); onoff does not have a member Computer, does it? So if your main module is written in ES6, you can do import Computer from "./onoff". Alternatively, export an element that also exports Computer`.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.