[英]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.