Tag: 打字稿

Typescript – 有没有办法指定一个全局引用?

我正在开发一个node.js脚本使用typescript,为了不至于抱怨非浏览器js代码,如require或module.exports ,我必须包括/// <reference path="lib/node.d.ts" />在每个文件中。 更糟糕的是,该文件的位置需要相对于代码文件,所以我不能轻易将其放到模板中。 有没有办法告诉tsc指定的目录中的每个文件符合节点定义?

使用TypeScript和Sails.js是给的问题,TypeError:对象不是一个函数

转换我的Sails.js应用程序使用TypeScript,当我尝试打我以前的路线,我得到“TypeError:对象不是一个函数”的错误。 我使用Class创build了一个控制器,并在TypeScript中重写了我的函数。 最后我实例化了我的新控制器 var controller = new TestController(); export = controller; 我不明白我在这里做错了什么。 我参考了http://alexclavelle.blogspot.com/2015/03/using-sailsjs-with-typescript.html?showComment=1435617822375所做的工作 还是没有…我猜测这是与生成的es5代码的东西。

在TypeScript文件中使用node.d.ts时编译错误

我正在研究我的第一个node.js项目(用于学习的目的),我希望使用TypeScript作为Visual Studio代码的select语言(是的,我不是在寻找简单的方法)。 源代码在这里: https : //github.com/thecoderok/ukrbash-node当我在源代码中引用node.d.ts时,我得到了大量的编译 错误如:urkbash-node \ typings \ node \ node.d.ts(178,36):错误TS1005:';' 预期。 urkbash-node \ typings \ node \ node.d.ts(425,5):错误TS1008:意外的标记; 'module,class,interface,enum,import or statement'expected。 urkbash-node \ typings \ node \ node.d.ts(425,12):错误TS1008:意外的标记; 'module,class,interface,enum,import or statement'expected。 urkbash-node \ typings \ node \ node.d.ts(425,17):错误TS1005:';' 预期。 有谁知道为什么以及如何解决它?

在Typescript中通过Webpack导入Jade模板

我试图抓住目前的前端技术,并希望使用Webpack加载Jade模板。 使用Javascript,这个按预期工作。 app.js : import * as foo from "html!jade-html!./header.jade"; document.write(foo.default); 但是,如果我把它重命名为app.ts ,内容不变, webpack要构build: ERROR in ./app.ts (5,22): error TS2307: Cannot find module 'html!jade-html!./header.jade'. 我很惊讶模块加载语义会突然改变使用TypeScript。 是什么赋予了? 奖励积分:这个Jade加载片断可以写得更短吗?

无法导入lodash

我是新来的TypeScript和我在加载lodash时遇到问题。 这是我的代码: ///<reference path="../../typings/lodash/lodash.d.ts"/> ///<reference path="../interfaces/IScheduler.ts"/> import _ = require('lodash'); module MyModule { export class LeastUsedScheduler implements IScheduler { /// CODE HERE } } 我尝试通过以下方式replace导入行: import * as _ from lodash; 在这两种情况下,我得到: "error| Cannot find name 'IScheduler'." 当我删除导入指令时,它编译完美,但_在运行时未定义。 我也尝试把模块导入到模块中,但没有成功。 我很抱歉这一定是一个非常愚蠢的问题,但我无法弄清楚。 谢谢 编辑: 我明白了这个问题。 引用lodash的input在范围中创buildvariables_ 。 这就是为什么编译没有import线罚款。 问题是引用input不真的导入lodash。 这就是为什么它在运行时失败。 当我导入lodash时,编译失败,因为lodash已经在范围之内。 感谢您的支持。

通过NodeJS中的依赖项对TypeScript文件进行sorting

我有一些文件,其中一些有依赖,其中一些没有。 也有cicle依赖关系。 我想通过这个依赖来sorting这个文件,以后按照正确的顺序连接文件。 这是TypeScript文件,但我收集了一个NodeJS程序中我想对TypeScript文件进行sorting的所有文件。 例子(这只是随机的名字):

Babel + Typescript + NPM模块+ Webpack

你好,我尝试从我的脚本脚本需要angular度,我得到这个错误: error TS2307: Cannot find module 'angular'. 这是我的webpackconfiguration文件: context: __dirname + '/client/js', entry: './script.ts', output: { filename: 'build.js', path: options.BUILD ? 'dist' : 'dev' }, module: { loaders: [ {test: /\.ts(x?)$/, loader: 'babel-loader!ts-loader'} ] } 编辑: 然后,在我的script.ts文件中,我这样做: import angular from 'angular'; 甚至var angular = require('angular'); 给了我相同的结果 我没有任何tsconfig.json文件 谢谢 !

Node的WebStorm代码完成显示了太多的选项

我用NodeJS和TypeScript代码创build了一个小型项目。 在那里安装了types定义文件(tsd install node)。 代码从这些行开始: var http = require('http'); var server = http.createServer(…) 当我在WebStorm 11中打开这个代码时,当我在http之后点击CTRL-Space时,它会在上下文相关的帮助窗口中显示数百个选项。 我尝试添加/// <reference path="typings/node/node.d.ts" />作为第一行,下载并安装了DefinitelyTyped社区存根,但仍然显示了大量的http对象选项。 当我在Visual Studio Code中打开同一个文件时,它显示了一个与Node的http模块相关的简短API列表。 如何教WebStorm更聪明的代码完成?

我如何得到这个Typescript Webpack项目编译没有错误?

我试图将我的工作webpack node.js项目中的两个.js文件转换为.ts文件并编译它(actions.ts和flux.ts)。 运行时 webpack –progress –colors 我得到这个错误: 错误在./src/app/tools/flux.ts (2,11):错误TS2304:找不到名称'require'。 错误在./src/app/tools/flux.ts (4,1):错误TS2304:找不到名称“模块”。 错误在./src/app/actions/actions.ts (2,12):错误TS2304:找不到名称'require'。 错误在./src/app/actions/actions.ts (11,1):错误TS2304:找不到名称“模块”。 我该如何解决这些问题? 在这个屏幕截图中,您可以看到我的文件夹结构以及我正在尝试编译的代码: 这是我的webpackconfiguration,如果有帮助: 'use strict'; var webpack = require('webpack'); var HtmlWebpackPlugin = require('html-webpack-plugin'); var CopyWebpackPlugin = require('copy-webpack-plugin'); var path = require('path'); var rootPath = __dirname; //site var srcPath = path.join(rootPath, 'src'); //site/src module.exports = { bail: true, cache: true, context: […]

Typescript:从另一个模块的类中添加一个方法/从不同模块填充一个名称空间

故事 我正在build立一个math运算模块库。 我也想把这个库分成多个模块: core , relational , vectors等等。 这些模块可以单独使用(但都取决于core模块) 我知道这是不可能使用部分类如何将TypeScript类分成多个文件? / https://github.com/Microsoft/TypeScript/issues/563 问题 : core模块定义了Set类,它是一个math集。 它定义了诸如Set#add , Set#remove 。 但是, 可选的 relational模块在Set类上添加了Set#product运算符。 其他模块也可以在Set类中添加其他操作。 我想保持添加function的可能性,当我看到适合。 这个问题 使用打字稿 ,我怎样才能添加一个方法在另一个模块居住的类? 我如何安排types,以便我的图书馆用户只有在安装了relational模块的情况下才能在代码完成中看到Set#product ? 否则,他只看到#add和#remove操作? 我正在开发node.js这个库,但也使用browserify捆绑它的浏览器使用。 // core/set.ts export class Set { add(element){} remove(element){} } // relational/set.ts import {Set} from './../core/set.ts'; Set.prototype.product = function(){} // ? // app/index.js import {core} […]