无法在 TypeScript 中引用外部模块
Unable to refer external module in TypeScript
我想在 TypeScript 脚本的 TypeScript code, but it is failing. Specifically, I want to use methods from the referring external.d.ts 文件中使用外部模块。
我的代码是:
module test {
//This is not working. I want to know the syntax to refer to express here.
private express: typeof express = require("express");
export testserver
{
constructor(private app:express.Application)
{
//Can not find express symbol
}
}
//This is not working. I want to know the syntax to refer to express here.
private express: typeof express = require("express");
使用import
:
import express = require("express");
export testserver
{
constructor(private app:express.Application)
{
}
}
并且不要混用内部和外部模块。更多内容在 YouTube 视频 TypeScript Modules Demystified: Internal, AMD with RequireJS, CommonJS with Node.js.
这甚至适用于
import * as express from 'express';
但问题是有时我 compile.Is 得到空白的 javascript 文件,这是一个已知问题?我是打字稿的新手,如果有任何问题请纠正我 wrong.Thank 你。
我想在 TypeScript 脚本的 TypeScript code, but it is failing. Specifically, I want to use methods from the referring external.d.ts 文件中使用外部模块。
我的代码是:
module test {
//This is not working. I want to know the syntax to refer to express here.
private express: typeof express = require("express");
export testserver
{
constructor(private app:express.Application)
{
//Can not find express symbol
}
}
//This is not working. I want to know the syntax to refer to express here.
private express: typeof express = require("express");
使用import
:
import express = require("express");
export testserver
{
constructor(private app:express.Application)
{
}
}
并且不要混用内部和外部模块。更多内容在 YouTube 视频 TypeScript Modules Demystified: Internal, AMD with RequireJS, CommonJS with Node.js.
这甚至适用于
import * as express from 'express';
但问题是有时我 compile.Is 得到空白的 javascript 文件,这是一个已知问题?我是打字稿的新手,如果有任何问题请纠正我 wrong.Thank 你。