typescript 我如何安装列出的类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36586452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:24:33  来源:igfitidea点击:

how do i install a listed typings?

typescripttsd

提问by dcsan

I'm using a library with Typescript, and getting a compiler error.

我正在使用带有 Typescript 的库,并收到编译器错误。

public/components/chatlogs.ts(25,19): error TS2304: Cannot find name 'Handsontable'.

public/components/chatlogs.ts(25,19): 错误 TS2304: 找不到名称“Handsontable”。

it seems there is a typings for it:

它似乎有一个类型:

$ typings search handsontable
Viewing 2 of 2

NAME                SOURCE HOMEPAGE                  DESCRIPTION UPDATED                 
handsontable        dt     https://handsontable.com/             2016-04-12T15:30:16.000Z
jquery-handsontable dt     http://handsontable.com               2016-03-29T17:54:46.000Z

but then i cant install that?

但后来我不能安装?

$ typings install handsontable
typings ERR! message Unable to find "handsontable" for "npm" in the registry. Did you want to install ambient typings with the ambient flag? If you can contribute these typings, please help us: https://github.com/typings/registry
typings ERR! caused by https://api.typings.org/entries/npm/handsontable/versions/latest responded with 404, expected it to equal 200

typings ERR! cwd /Users/dc/dev/rikai/boteditor
typings ERR! system Darwin 15.3.0
typings ERR! command "/usr/local/bin/iojs" "/usr/local/bin/typings" "install" "handsontable"
typings ERR! node -v v5.1.1
typings ERR! typings -v 0.7.12

typings ERR! If you need help, you may report this error at:
typings ERR!   <https://github.com/typings/typings/issues>
?  boteditor git:(master) ? 

Is there some way to use a different "source" than npm?

有什么方法可以使用与 npm 不同的“源”吗?

typings help install

Usage: typings <command>

Commands:
    bundle, i, in, info, init, install, la, list, ll, ls, open, r, remove, rm,
    search, uninstall, view

typings <command> -h   Get help for <command>
typings <command> -V   Enable verbose logging

typings --version      Print the CLI version

[email protected] /usr/local/lib/node_modules/typings

How do I install a typings that is listed with a different homepage?

如何安装与不同主页一起列出的类型?

Or maybe they exist for tsd but not typings?

或者它们可能存在于 tsd 而不是类型?

回答by dcsan

I believe globalhas replaced ambientas a keyword, and source~packagenameis the syntax, for example:

我相信global已替换ambient为关键字,并且source~packagename是语法,例如:

typings install dt~node --global

still unclear what the envor dttypings repo distinctions are. surely dtis the default place that is searched, so why is there a need to specify it?

仍然不清楚envor 类型dtrepo 的区别是什么。肯定dt是搜索的默认位置,那么为什么需要指定它呢?

回答by basarat

but then i cant install that

但后来我无法安装

Type definitions in DefinitelyTyped are considered ambient. So you need to install with the ambient flag:

考虑了绝对类型中的类型定义ambient。所以你需要安装环境标志:

typings install --ambient handsontable

More on ambient

更多关于环境

When to use ambient while searching for a type definition?

搜索类型定义时何时使用环境?

回答by Ajay

You can directly copy a typings file from Definitely Typed Typescriptand paste it in your project.

您可以直接从绝对类型打字稿中复制打字文件并将其粘贴到您的项目中。

You can also download the whole definitely typed github project from above link, copy and paste the required typings files according to your need.

您也可以从上面的链接下载整个确定类型的 github 项目,根据需要复制并粘贴所需的类型文件。

As @basarat told

正如@basarat 所说

typings install --ambient fileName 

would be an another option to download typings file.

将是下载打字文件的另一种选择。

For more info on typings file, like how to use them, what they contain look at Definitely Typed.

有关打字文件的更多信息,例如如何使用它们,它们包含的内容,请查看绝对类型

Regards

问候

Ajay

阿杰

回答by unional

The ERR message actually suggest what you should do (adding line breaks for SO):

ERR 消息实际上建议您应该做什么(为 SO 添加换行符):

$ typings install handsontable
typings ERR! message Unable to find "handsontable" for "npm" in the registry.
Did you want to install ambient typings with the ambient flag?
If you can contribute these typings, please help us: https://github.com/typings/registry

To get the help message on typings, you should do

要获得有关打字的帮助消息,您应该这样做

typings <command> -h

In this case

在这种情况下

typings install -h

typings install (with no arguments, in package directory)
typings install [<name>=]<location>

  <name>      Module name of the installed definition
  <location>  The location to read from (described below)

Valid Locations:
  [<source>!]<pkg>[@<version>][#<tag>]
  file:<path>
  github:<org>/<repo>[/<path>][#<commitish>]
  bitbucket:<org>/<repo>[/<path>][#<commitish>]
  npm:<pkg>[/<path>]
  bower:<pkg>[/<path>]
  http(s)://<host>/<path>

  <source>    The registry mirror (E.g. "npm", "bower", "env", "global", "dt", ...)
  <path>      Path to a `.d.ts` file or `typings.json`
  <host>      A domain name (with optional port)
  <version>   A semver range (E.g. ">=4.0")
  <tag>       The specific tag of a registry entry
  <commitish> A git commit, tag or branch

Options:
  [--save|-S]       Persist to "dependencies"
  [--save-dev|-D]   Persist to "devDependencies"
  [--save-peer|-P]  Persist to "peerDependencies"
  [--ambient|-A]    Install and persist as an ambient definition
    [-SA]           Persist to "ambientDependencies"
    [-DA]           Persist to "ambientDevDependencies"
  [--production]    Install only production dependencies (omits dev dependencies)

Aliases: i, in

Is there some way to use a different "source" than npm?

有什么方法可以使用与 npm 不同的“源”吗?

You can configure the defaultSourceand defaultAmbientSourcein .typingsrc.

您可以配置defaultSourcedefaultAmbientSource.typingsrc

回答by Michael Ganesan

try using the following command if there is a source for dt or env

如果有 dt 或 env 的来源,请尝试使用以下命令

typings install --global en~node

打字安装 --global en~node