我想为我的库创建类型,它使用来自<script>的外部API。如果我构建库(ng build angular8-yandex-maps --prod),一切正常,但是当我尝试在Angular应用程序中导入构建的库时,它失败了- Cannot find namespace 'ymaps',Cannot find type definition file for 'yandex-maps'等。
声明的命名空间不包含在构建中,是否可以包含它?
dist/**/*.component.d.ts
Cannot find type definition file for 'yandex-maps'
/// <reference types="yandex-maps" />再生产
https://github.com/ddubrava/angular8-yandex-maps/tree/feature/custom-typings
typings/yandex-map/index.d.ts
declare namespace ymaps {
...
}tsconfig.lib.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": ["yandex-maps"],
"typeRoots": ["../../node_modules/@types", "src/lib/typings"],
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": ["src/test.ts", "**/*.spec.ts"]
}发布于 2020-11-24 00:38:42
.d.ts将不会被复制,您应该改用.ts +在public-api.ts中添加<reference />。因此,编译器将在public-api.d.ts中创建dist/**/typings/yandex-maps/index.d.ts和<reference />。
更多信息:Typescript does not copy d.ts files to build
tsconfig.lib.json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": ["src/test.ts", "**/*.spec.ts"]
}typings/yandex-map/index.ts
declare namespace {
...
}public-api.ts
// <reference path="./lib/typings/yandex-maps/index.ts" />更新:
ESLint:不要对./lib/typings/yandex-maps/index.ts使用三重斜杠引用,请使用import样式的instead.(@typescript-eslint/triple-slash-reference)
import './lib/typings/yandex-maps/index';https://stackoverflow.com/questions/64957644
复制相似问题