问题标签 [typescript-typings]

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 投票
1 回答
319 浏览

typescript - 应该打字吗?如果不是,如何在不破坏用户的情况下在 npm install 上触发类型安装?

我有一个 npm 包 (X),它是用 Typescript 编写的,并使用通过 typings 安装的类型

我没有提交由typings 生成的typings 目录,因为我有一个typings.json,typings 工具可以从中重新生成该目录。事实上,我添加了 Typings 作为 devDependency 和一个 npm 脚本“postinstall”来运行“typings install”,所以任何新开发人员都可以在新结账时运行“npm install”后进行所有设置。

问题是,有另一个包使用这个包(例如Y)。当用户转到“npm install Y”时,他们拉下 X 并且“postinstall”脚本正在他们的机器上运行。Typings 是一个 devDependency,所以它不会被下载(我也不希望它适合他们——他们不是在 X 上开发的)。他们也没有全局安装打字,所以他们安装的 Y 错误。

什么是正确的解决方案?我应该提交打字吗?或者是否有另一个 npm 生命周期脚本仅在安装后运行没有 args 的“npm install”?或者是其他东西?

谢谢!

0 投票
2 回答
2117 浏览

typescript - dt~react-router 错误 TS2503:找不到命名空间“HistoryModule”

我尝试使用 下载 React-Router 类型定义typings install --save --global dt~react-router,但我的代码仍然无法编译,因为类型/globals/react-router/index.d.ts 引用的 HistoryModule 不存在。

早些时候我被推荐使用typings --save react-router,但是虽然这包括可怕的“HistoryModule”,但它缺少 React Router 元素通常具有的属性的其他关键类型定义(缺少 Route 元素道具的 onChange 属性)。我需要下载其他内容才能使其正常工作吗?另外,我怎么知道我是否需要下载多个其他全局类型定义才能让另一个工作,因为我不知道任何方式,并且类型命令似乎不理解全局类型定义是否依赖于其他模块。

0 投票
1 回答
141 浏览

typescript - 当我在 Visual Studio 中使用 tsconfig 时,我得到编译器错误,但是当我删除它时,我没有

您好,当我使用自定义 tsconfig 而不是 Visual Studio 自动为我设置的那个时,这个项目没有拾取 typescript 定义文件。

https://github.com/jvelezc/GridStackDemo/tree/master/src/GridStackDemo

问题是 tsconfig 如何改变类型定义的发现能力?

我有一个非常简单的 tsconfig

如果我使用它(而不是用于配置打字稿选项的默认 Visual Studio 内置功能),那么我的类型定义没有被读取,并且我得到 angular 没有定义。

当我使用它时,请注意它说找不到名称 angular 在此处输入图像描述

当我不使用它时 在此处输入图像描述

如果我拖动类型定义 /// 那么它可以工作。问题是 tsconfig 如何改变类型定义的发现能力?

0 投票
0 回答
33 浏览

reactjs - 模块类型定义依赖全局一

我已经使用以下命令安装了 reacttype 定义

所以我把它放在文件夹里

对于 react-dom,只有可用的全局模块,可以使用命令安装

它进入文件夹

现在 React-Dom 无法找到反应定义,因为它希望在全局文件夹中找到它。处理这种情况的假定方法是什么?

老实说,我不知道全局定义和模块定义之间的区别......而且 Typings 自述文件没有解释它。
我开始使用 npm 定义,因为它们是最新的。

0 投票
1 回答
544 浏览

momentjs - Aurelia 的“打字安装时刻”失败

很简单:通过 Typings 安装 moment 失败:

与'无法在注册表中找到“时刻”(“npm”)......'在其他帖子中有些人说要使用'--ambient',如下所示:

虽然这有效,但它损坏了我的 Aurelia 模块 ts 文件。它改变

它在每个模块文件中都这样做,这使得应用程序失败 b/c 它不再识别 Aurelia 框架模块。所以 --ambient 标志不好,我只需要通过 Typings 安装基本的 moment.d.ts 文件。

任何想法如何让 Typings 安装时刻?

0 投票
1 回答
67 浏览

typescript - 3rd 方应用程序级别的临时类型

关于如何让自定义类型在anuglar2 快速入门项目中工作的一些事情。

我以outlayerhttps://github.com/metafizzy/outlayer为例。

我已配置systemjs为加载依赖项。它是可用的,import * as outlayer from "outlayer";但我仍然得到编译错误Cannot find module 'outlayer'.

为了解决这个问题,outlayer.d.ts直接在node_modules/outlayer目录中添加了一个类型文件并更新了package.json包含"typings": "./outlayer.d.ts",.

出于显而易见的原因,将此文件直接添加到 node_module 并不理想。有什么更好的方法来处理这个而不必分叉库?更好的是,我怎样才能在应用程序级别进行简单/快速的打字,这样我就不必担心马上写出整个事情?例如,如果我现在尝试使用该data功能,我会看到Property 'data' does not exist on type 'typeof Outlayer'

总之,只需要能够编写一个自定义的应用程序级别的类型,它没有所有的好东西,但也不会出现所有的错误。一种临时打字。

谢谢!

0 投票
1 回答
118 浏览

javascript - Command for Typings CLI utility to make typings folder match typings.json

I have a large team working on a repo using Typescript, and nobody checks in the /typings folder into the team's shared repository, they only check in the typings.json file which specifies the version information for each definition set required by the project.

Sometimes someone will delete a definition set from typings.json, since the part of the project they are working on no longer uses that library (or we found a better definition set), using
typings uninstall --global --save dt~whatever, and that works fine on their local machine, BUT when they push up the new typings.json and I or someone else pulls it down, when we then run typings install, the command only adds new definitions to the typings folder, and does not delete definitions from the typings folder which are no longer present in typings.json.

Is there a command which I can run to both add new definition sets and delete removed sets by diffing the current typings.json from the state of typings.json when the typings command was last run?

Currently we just have everyone delete the entire typings folder and run typings install again each time they pull, but that is getting to be a bit inefficient, since we have a lot of definition sets now.

NOTE: we tried typings uninstall and typings uninstall --save but those just throw errors (it seems you may only specify specific definition sets to uninstall).

0 投票
5 回答
57657 浏览

jquery - Typescript 和 JQuery 编译错误:找不到名称“$”

我正在用 jquery 测试 typescript,但是当我编译 test.ts 文件时,它总是给我一个错误提示:找不到名称'$'。

我已经导入了 jquery 并添加了它的定义参考。如果我import $ = require("jquery")在我的文件中使用,编译时会出现test.ts另一个错误“ ”。但是,JQuery 文件夹已经存在于 node_modules 文件夹中。Cannot find module jquerytsc

有谁知道在打字稿中使用 jquery 的正确方法是什么?

以下是我的步骤:

  1. 使用安装 jquerynpm install jquery --save
  2. 使用安装类型和 jquery 定义typings install --global --save dt~jquery
  3. 在 test.ts 顶部添加 jquery 引用/// <reference path="../../../typings/globals/jquery/index.d.ts" />

tsconfig.json

测试.ts

0 投票
1 回答
1088 浏览

typescript - Angular 2 - npm3 安装打字错误

每当我尝试 sudo npm install Angular 2 模块都会更新并安装得很好但是当类型安装尝试运行时我会得到以下信息

我已经使用提升的权限在全球范围内安装了 npm 和 typings

包.json

打字.json

0 投票
2 回答
9070 浏览

typescript - 如何在 Angular 2 中包含打字稿自定义类型定义?

我不明白自定义类型定义文件如何包含在打字稿应用程序中。例如,此应用程序具有src/custom-typings.d.ts包含自定义类型定义的文件。这个文件是如何包含的?

我试图重命名这个文件,它仍然包含在内。文件扩展名可以是*.ts(不仅仅是*.d.ts)。webpack 会*.ts在项目的每个文件中搜索类型定义吗?如果是这样,那么如何改变这种行为?如何告诉 webpack 在特定文件中搜索类型定义?