tune2fs tune2fs - 1 year ago 1211
Javascript Question

How to import a js library without definition file in typescript file

I want to switch from js to typescript, as the project gets larger.

However we have lots of library's as amd Modules which we do not want to change to typescript.

However we want to import them into typescript files, however we also do not want to generate the definitons file. How can we achieve that?

e.g. The new Typescript file:

/// <reference path="../../../../definetelyTyped/jquery.d.ts" />
/// <reference path="../../../../definetelyTyped/require.d.ts" />
import $ = require('jquery');
import alert = require('lib/errorInfoHandler');

Where lib/errorInfoHandler is an amd module of an huge js library, which we do not want to touch.

However this produces the following errors:

Unable to resolve external module ''lib/errorInfoHandler''
Module cannot be aliased to a non-module type.

This should actually produce the following code:

define(["require", "exports", "jquery", "lib/errorInfoHandler"], function(require, exports, $, alert) {


Is there a way to import a js library into typescript as amd Module and use it inside the typescript file. Without the need to make a definition file.


A combination of the 2 answers given here worked for me.

declare module "lib/errorInfoHandler" {
   var noTypeInfoYet: any; // any var name here really
   export = noTypeInfoYet;

I'm still new to TypeScript but it looks as if this is just a way to tell TypeScript to leave off by exporting a dummy variable with no type information on it.