如何使用带有Browserify的打字稿模块? [英] How to use typescript modules w/ browserify?

查看:74
本文介绍了如何使用带有Browserify的打字稿模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是打字机的新手,目前正在使用带有浏览器帮助的CJS。当我向混音中添加打字稿时,TSC编译器抱怨要求说

I'm new to typescript and I'm currently using CJS w/ help from browserify. When I added typescript to the mix the TSC compiler complains about require saying

error TS2095: Could not find symbol 'require'

这是我进行browerify的入口点

This is my entry point for browerify

var Hello:any = require('hello.js').Hello;

这是我的hello js文件(上面需要)

here is my hello js file (required above)

var React = require('react');

var Hello = React.createClass({displayName: 'Hello',
    render: function() {
        return React.DOM.div(null, "Hello ", this.props.name);
    }
});

exports.Hello = Hello;


推荐答案

感谢@AlexB的回复。将def添加到我的app.ts顶部,如下所示:

Thanks to @AlexB for his reply. Adding the def to the top of my app.ts like I show below solved this issue

///<reference path='../typings/node.d.ts' />

var Hello:any = require('hello.js').Hello;

更新

这也值得一提...如果您不希望/不想拥有打字信息,可以按以下步骤忽略它

It's also worth a mention ... if you don't want/care to have the typing information you can omit it as follows

declare var require:any;

var Hello:any = require('hello.js').Hello;

这篇关于如何使用带有Browserify的打字稿模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆