问题标签 [typescript2.0]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
30 浏览

angularjs - AspCore - 不尊重 tsconfig

我创建了一个新的 asp 核心项目。我想在其中使用 typescript 2.0 和 angular 2。

我在全球范围内安装了打字稿并将其放在包中

该项目可以使用 gulp 编译,结果我看到一个有效的 javascript 文件

但是在 VisualStudio 的 IDE 中,我收到错误,表明未加载 tsconfig。尽管如此,我在虚拟打字稿项目中看到了 tsconfig,所以我认为它已被加载。

我还可以看到依赖项有一个警告信号,但是所有的 pacakges 都已安装。并且当我运行重新安装时没有重要错误

在此处输入图像描述

我的项目结构看起来像这样

在此处输入图像描述

我的 tsconfig 有这个内容

0 投票
1 回答
271 浏览

javascript - 升级到 typescript 2 后找不到 (string)、Object、Date、Json 的要求索引

从 1.8 转换为 typescript 2.0 后,我遇到了很多错误。错误和打字稿代码是。

找不到“JSON”

属性 'indexOf' ,类型 'string' 上不存在 concat

找不到名称“对象”

在 Array() 中找不到数组

找不到日期

也存在诸如 require 和 Promise 之类的问题,但在添加 shim 和 types 后解决了

tsconfig.json

{ "compilerOptions": { "module": "commonjs", "target": "es6", "outDir": "out", "noLib": true, "sourceMap": true }, "exclude": [ "node_modules" ] }

0 投票
1 回答
90 浏览

typescript - 在解构参数中键入默认参数

我最喜欢的 es6 特性之一是能够使用解构参数。例如:

但是,当需要将显式类型分配给其中一个参数时,typescript 编译器会生成错误(例如,使其具有比默认推断更大的灵活性):

我发现解决这个问题的唯一方法是显式键入整个参数集 - 当可以推断出剩余的参数类型时,这似乎过于复杂:

想法?有没有我缺少的 #2 的简单性来完成 #3 的语法?

0 投票
1 回答
1506 浏览

express - 打字稿 2.0 @Types/Express | 找不到模块

npm install @types/expressTypescript 2.0 的 Express 类型定义在运行后执行和tsc -t ES6ES6时会导致意外错误。代码在没有 ES6 标志的情况下编译得很好。谁能解释一下?我也有其他类型定义的问题,例如ssh2.

以下是重现的步骤:

到目前为止一切都很好。

现在事情开始变糟了

好的,我最好确保安装了 serve-static 和 mime 的类型。

奇怪的是我得到了一个错误!代码但类型已下载,让我们再次尝试编译

和上次一样的错误。

我的环境:

  • 视窗 10
  • 节点 v6.6.0
  • TSC 2.0.3

具有相同问题的其他定义:

0 投票
1 回答
255 浏览

typescript2.0 - Typescript 2.x:如何修复“找不到名称错误”

我正在使用 gulp 来转录打字稿文件。

这是吞咽任务:

在我的项目文件夹中有一个 tsconfig.json:

我想在 node_modules/@types 中使用 typescript 包,所以我用 npm 安装了它们。

但它不起作用。我总是收到类似的消息

错误 TS2304:找不到名称“角度”

怎么了?我怎样才能得到原因?

0 投票
3 回答
1169 浏览

asp.net-mvc - VS2015 does not have TypeScript template and it is not supporting typescript

I am working on Visual Studio 2015 professional. I have installed TypeScript using npm. TypeScript 2.0.3 installed. Then i tried to add a TypeScript file using Right Click on a tsScript Folder of my Project -> Add New Item but i did not find any TS file template. Then I make a workaround by adding a text file and changed its extension from .txt to .ts and pasted some TypeScript code in this file. When i am running the application, application is able to generate jsfile from this ts file. But the problem is : the text color in the ts file is all black. There is no coloring, no intellisense, no modularation . It is just plain text.

What can i do to make this ts file recognized to visual studio. Below is the screenshot.

enter image description here

tsconfig.json File :

EDIT: The issue resolved by updating my Visual Studio 2015 to Visual Studio 2015 Update 3.

0 投票
2 回答
15240 浏览

node.js - 如何将 Node.js 的 TypeScript 代码编译为一个文件?

与 Node.js 一起使用时,我想将 TypeScript 编译为一个文件。

我试过像这样配置“tsconfig.json”:

...但是当我尝试使用module" set to“commonjs”`时,我得到了错误:

如果我将其更改为"module": "system",则在以下位置运行文件时会出现此错误node

如果我更改module"amd",则在以下位置运行文件时会出现此错误node

0 投票
1 回答
5410 浏览

angular - 一个子组件中可以有多个@outputs 吗?我有两个,一个不工作

这是子组件:

子组件html:

父组件:

父 html:

onChanged 事件从孩子接收数据,但 onLoadFood 没有。按下子组件上的按钮会激活 LoadFoodRequest 函数并且不会出错,该事件永远不会到达父组件。有任何想法吗?

0 投票
1 回答
115 浏览

npm - 在@types 之外发布类型声明

我创建了一个 npm 库,但我不想在公共存储库中发布它(所以我不能使用 @typings npm 包将我的类型放在那里)。另一方面,我不想将.d.ts文件放入该包中,但想发布另一个名为lib-typings.

是否可以使用Typescript 2 中lib-typings调用的库?lib

0 投票
1 回答
461 浏览

angular - Angular2 应用程序无法在 IE 中使用 ES6,并使用 ES5 编译错误

我有一个使用打字稿(2.0.0)的angular2应用程序(2.0.0)。在我的 tsconfig 中,我使用这一行编译为 es6:

它在 Chrome 和 Edge 中运行良好,但在 IE11 中无法运行。

我将其更改为目标 es5,但随后出现几个编译错误,例如:

这确实会产生输出,并且在运行时似乎可以在 IE11 和其他浏览器中工作(但我还没有测试所有内容)。我仍然不喜欢编译错误。

我有 core-js 包括在内。我认为这是解决此问题的方法。

我应该瞄准 5 还是 6?

es6应该在IE中工作吗?有没有我缺少的垫片?

如何使用 es5 并摆脱编译错误?

这是我的 tsconfig.json: