7

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

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

似乎有一个类型:

$ 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

但是我不能安装它?

$ 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) ✗ 

有什么方法可以使用与 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

typings@0.7.12 /usr/local/lib/node_modules/typings

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

或者它们可能存在于 tsd 但不存在于类型中?

4

5 回答 5

13

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

typings install dt~node --global

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

于 2016-06-19T21:39:17.023 回答
1

但后来我无法安装

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

typings install --ambient handsontable

更多关于环境

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

于 2016-04-13T00:34:57.267 回答
0

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

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

typings <command> -h

在这种情况下

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

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

您可以配置defaultSourcedefaultAmbientSource.typingsrc

于 2016-04-13T05:44:57.013 回答
0

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

打字安装--global en~node

于 2016-06-15T21:34:50.807 回答
0

你可以直接从Definite Typed Typescript中复制一个打字文件并将其粘贴到你的项目中。

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

正如@basarat 所说

typings install --ambient fileName 

将是下载类型文件的另一种选择。

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

问候

阿杰

于 2016-04-13T04:09:57.813 回答