我有一个私有的NPM包提要我想用于范围包。
我已阅读过TypeScript文档的Publishing文章。我还尝试根据@types/jquery包创建包。
所以这就是我提出的:创建(并发布)一个名为" @ myscope / i18n"的包。它非常简单,包含一个.d.ts文件,其中包含一个全局接口I18N
的声明,其方法为translate(string)
。 tarball包含以下文件:
index.d.ts
/**
* Static members of I18N
*/
interface I18NStatic {
/**
* Returns the translation value based on the specified key
*
* @param key The translation key.
*/
translate(key: string): string;
}
declare module "i18n" {
export = I18N;
}
declare var I18N: I18NStatic;
的package.json
{
"name": "@myscope/i18n",
"version": "1.0.11",
"description": "TypeScript definitions for MyScope Translator",
"license": "MIT",
"main": "",
"repository": {
"type": "git",
"url": "https://myscope.visualstudio.com/example/_git/i18n"
},
"scripts": {},
"dependencies": {},
"peerDependencies": {},
"typeScriptVersion": "2.0"
}
我使用以下 package.json
在ASP.NET Core项目中使用它{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"@types/jquery": "2.0.48",
"@types/semantic-ui": "2.2.4",
"@myscope/i18n": "1.0.11"
}
}
但是当我尝试在我的TS文件中使用I18N.translate(string)
时,我总是会收到此错误
错误TS2304(TS)找不到名称' I18N'。 Example.UI.WebApp(tsconfig project)C:\ Users \ Sandro \ Source \ Repos \ example \ Example.UI.WebApp \ TypeScript \ Address.ts
当我在我的项目中直接使用index.d.ts(而不是通过npm)时,它完美地工作。但是一旦我再次删除它,它就会停止工作。我没有错误或警告在" Dependencies / npm"解决方案资源管理器视图中的项目部分。
我错过了什么?