简体   繁体   English

打字稿:如何在node_modules中导入和添加嵌套文件的输入?

[英]Typescript: How do I import and add typings for a nested file in node_modules?

installed with: 安装时:

npm install highcharts
typings install highcharts/highstock --ambient

index.ts: index.ts:

import * as Highstock from 'highcharts/highstock'
new Highstock() // Cannot use 'new' with an expression whose type lacks a call or construct signature.

tsconfig.json: tsconfig.json:

{
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "noEmitHelpers": true,
    "outFile": "./dist/index.js",
    "preserveConstEnums": true,
    "target": "es6"
  },
  "files": [
    "typings/browser.d.ts",
    "ty.d.ts",
    "src/index.ts"
  ]
}

for anyone that finds this question in the future, i needed to wrap the highcharts typings like so: 对于将来发现这个问题的任何人,我需要包含如下的高图类型:

declare module 'highcharts/highstock' {
  // typings go here
}

i assume there's some way to re-export the community typings from inside this declared module, but for now i'm manually adding typings as i go. 我假设有一些方法可以从这个声明的模块中重新导出社区类型,但是现在我正在手动添加打字。

new Highstock() // Cannot use 'new' with an expression whose type lacks a call or construct signature. new Highstock()//不能对类型缺少调用或构造签名的表达式使用'new'。

TypeScript definitions for JavaScript libraries are best effort (ie might not be up to date). JavaScript库的TypeScript定义是尽力而为(即可能不是最新的)。 That definition file ( https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/highcharts/highstock.d.ts ) does not support such usage. 该定义文件( https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/highcharts/highstock.d.ts )不支持此类用法。 If that is a usage that should be supported feel free to create a Github Pull Request 🌹 如果这是一个应该支持的用法,请随意创建一个Github PullRequest🌹

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Webpack 正在从我机器的全局“node_modules”导入模块。 如何让它只从我的项目的 `node_modules` 导入? - Webpack is importing modules from my machine's global `node_modules`. How do I get it to only import from my project's `node_modules`? 如何将 node_modules 中的新组件导入到项目中? - How an I import new components from node_modules into the project? 如何从项目的 node_modules 添加符号链接? - How do I add a symlink from project's node_modules? 如何切换到已保存到桌面的 node_modules 文件的本地版本? - How do i switch to a local version of a node_modules file that I've saved to desktop? 我是否必须将我创建并想要导入的任何脚本/模块放置在 node_modules 文件夹中? - Do I have to place any scripts/modules I create and want to import within the node_modules folder? 如何将 node_modules 下的节点安装模块中的模块添加到浏览器? - How can I add modules in node install modules under node_modules to browser? 如何使用browserify从node_modules加载typescript模块? - How do you load typescript modules from node_modules using browserify? 如何在我的 javascript 文件中从“node_modules”导入或使用已安装的模块 - How to import or use installed modules from 'node_modules' in my javascript file 如何将jQuery类型输入到打字稿 - How to import jquery typings to typescript 使用express node js时如何从node_modules导入包 - how can i import package from node_modules when use express node js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM