LoginSignup
1
2

More than 5 years have passed since last update.

TypeScript + Browserify で特定ライブラリが出力されない時の対処

Last updated at Posted at 2015-07-22

TypeScriptとBrowserifyを使ったPJで、require()や本体コードが出力されないライブラリやフレームワークがあり、ハマってしまったのでメモを残しておきます。

原因

型定義ファイルの記述が正しくない場合は、出力されません。

foobar.d.ts
interface FooBar {
    xxx:string;
    yyy:number;
}
declare var foobar:FooBar;
declare module "foobar" {
    export = FooBar; // NG
}
index.ts
/// <reference path="../typings/tsd.d.ts"/>
import _ = require('lodash');
import foobar = require('foobar');

console.log(_);
console.log(foobar);
index.js
var _ = require('lodash');

console.log(_);
console.log(foobar); // JavaScript Error

対処

下記のように正しく記述すれば、出力されるようになります。
大文字小文字を間違えないように注意。

foobar.d.ts
interface FooBar {
    xxx:string;
    yyy:number;
}
declare var foobar:FooBar;
declare module "foobar" {
    export = foobar; // OK
}
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2