TypeScript - how to type a self-instantiating function -


Function register is made by calling register ('some') immediately. Typuscript says that this is only possible when new is used on a zero return function in this case register own An example is returning me how should I type in typedcript?

  module register {export function register (x: string): example (if ((register this entry)) {new register (x)} .value = x} ... Export Interface Example {New (X: String): Example; ...}} = Export    

Maybe your example is simple, and you are trying to get some more complexity under the hood, but if I understand your code correctly, Without an operator, want to return an example of the register function.

The only option I can think is to run the TS compiler, and to specify the return type as zero, and then your variable Use any type.

  module register {export function register (x: string): zero {if this (this example of register!)) Return new register (x); } This.value = x;} export interface eg Rann {new (x: String): Example: Value: string;}} Export = register; Var Rega: Any = RegisterkRegister ( "a"); Console.log (rega.value); // something   

Update: Since there is a problem specifying any as a clear code for each variable, So you can use the object instead of the new operator. Create ():

  module register {export function register (x: string): example {var r = Object.create (register); R.value = x; Return r; } Export Interface Example {New (X: String): Example; Value: string; }} Export = Register; Var rega = register Registrar ("some"); Console.log (rega.value); // some    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -