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
how do i install a listed typings?
提问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 global
has replaced ambient
as a keyword,
and source~packagename
is the syntax, for example:
我相信global
已替换ambient
为关键字,并且source~packagename
是语法,例如:
typings install dt~node --global
still unclear what the env
or dt
typings repo distinctions are. surely dt
is the default place that is searched, so why is there a need to specify it?
仍然不清楚env
or 类型dt
repo 的区别是什么。肯定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
更多关于环境
回答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 defaultSource
and defaultAmbientSource
in .typingsrc
.
您可以配置defaultSource
和defaultAmbientSource
在.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