Are you allowed to specify return types for a class constructor?

Topics: General
Nov 15, 2012 at 11:13 PM
Edited Nov 15, 2012 at 11:15 PM

Is there a correct syntax to specify a return type for a ctor?

In this simple example I can't seem to get that working:



class Test { 
  constructor(): string { 



Gives a compiler error,  Expected "{"



class Test {
	constructor() => Test {


Causes the playground to throw errors:


SKIPPING refresh because models are weird editor.main.js:10
Object {message: "RangeError: Maximum call stack size exceeded"} editor.main.js:10


Interfaces are allowed to define a constructor with a return type:


interface MyInterface {
    new () : any;


How would you implement this interface correctly?

Nov 16, 2012 at 12:03 AM

Answered back on StackOverflow: