This project is read-only.


Callable modules not working in TS 0.9


This is valid code in TS0.8:
declare module "express" {
    export function (): number;

import x = module("express");
Which does not work in TS0.9 probably as a module no longer creates a type.

This is required by a number of nodeJS modules. e.g. express

import express = module('express')
var app = <express.ServerApplication> express()
The new design covered at caters for creating callable modules however the syntax for declaring a callable modules that can also be loaded via import is still open.
Closed May 24, 2013 at 6:08 PM by paulb
the declare syntax is the following...
declare module 'express' {
    function someName() : number;

    export = someName;


Jantrim wrote May 22, 2013 at 1:07 PM

+1, also required for jQuery

declare module "jquery" {
export function (selector: string, context?: any): JQuery;

and accoding to require spec, it is possible to export functions

also commonjs talks about factory as a function

Jantrim wrote May 22, 2013 at 1:26 PM

import jq = module("jquery");
import jq = module("jquery");
noop() or noConflict() call required for workitem

paulb wrote May 22, 2013 at 6:43 PM

This is by design see the discussion here:

for the new design.

** Closed by paulb 05/22/2013 10:43AM

schungx wrote May 26, 2013 at 5:26 AM

Hi @paulb,

Just tried out the latest 0.9-release (typescript-aeda9c0df4d45816f1ce0026ef81a514dbd6cf8a).

Still gets "error TS1063: Export assignments cannot be used in internal modules." on the line with "export =".

schungx wrote May 27, 2013 at 3:29 PM

Sorry. Problem SOLVED. It errors out if the module name is not put in quotes. It works if the module name is in quotes.

EisenbergEffect wrote Jul 3, 2013 at 2:01 AM

I'm not sure this should be so hastily closed. Regarding jQuery and callable modules (and express and others as well...) I see that you can export the function, but what if there are many overrides of the function which all need to be exported? That is the case with jQuery and I would bet with many Node.js modules as well. What is the syntax for that?

arek_bal wrote Jul 3, 2013 at 11:46 AM

Other problem is that you can not export other symbols that way.
So your exported function can not return "internal" JQuery object.

Scriby wrote Feb 11, 2014 at 5:56 PM

For anyone who finds this in the future and just wants to know how to create a callable module, it really helped me to look at the express type definitions here.