Cannot instantiate a type script class in another file. Error: ts2351


Problem: I cannot seem to instantiate a new instance of a type script class which I am importing from another file.

Explanation: I am writting a node application in type script which uses the express module. These classes are in external files as to encapsulate the routing of express.

The file 'masterRoute.ts' is to forward any incoming http requests to their intended route.ts file.

The file 'indexRoute.ts' is the intended route file for the url: ''.

Aim: For learning purposes, I am trying to make an instance of the external IndexRoute class in the MasterRoute class.



import express = require('express');
export class IndexRoute{
    private _ejsFilePath: string = 'views/index.ejs';
    private request: express.Request;
    private response: express.Response;
    constructor(request: express.Request, response: express.Response){
        this.request = request;
        this.response = response;
    public renderFile(): string{
            return null;
            return error;


import express = require('express');
import * as IndexRoute from './indexRoute';
export class MasterRoute{
    private Router: express.Router;
        this.Router = new express.Router();
    public onHttpRequest(request: express.Request, response: express.Response){
        // I have tried to use all of the lines below one by one. 
        // None of them work.
        // let test: IndexRoute = new IndexRoute(request, response);
        // let test: = new IndexRoute(request, response);
        // let test = IndexRoute(request, response); 

Show source
| class   | node.js   | express   | typescript   | instantiation   2017-01-07 07:01 0 Answers

Answers ( 0 )

◀ Go back