gpt4 book ai didi

angular - 使用自己的类型发布 angular 包 - 类型引用包含错误的路径

转载 作者:行者123 更新时间:2023-12-04 13:26:43 31 4
gpt4 key购买 nike

我写了一个 Angular 库,其中包含 DailymotionPlayerComponent .该库基本上插入了https://api.dmcdn.net/all.js脚本进入 DOM 然后调用 DM.player(element, {})设置组件。 The code is hosted here .

git clone https://github.com/MintPlayer/mintplayer-ng-dailymotion-player
cd mintplayer-ng-dailymotion-player
npm install
npm start -- --open
我的库的类型位于 /src文件夹 as documented here如果库没有可用的类型... 部分。
但是,在新的 angular 项目中安装包时,该项目不会构建。
ng new dailymotion-test --routing=false --style=scss --strict
cd dailymotion-test
npm install --save @mintplayer/ng-dailymotion-player
npm install --save @mintplayer/ng-player-progress
code .
接下来是代码:
导入 DailymotionPlayerModuleAppModuleapp.component.html:
<div class="content">
<span>ng-dailymotion-player-demo app is running!</span>
<dailymotion-player [width]="400" [height]="300" #dmplayer></dailymotion-player>
</div>
app.component.ts
export class AppComponent implements AfterViewInit {
title = 'dailymotiontest';

@ViewChild('dmplayer') dmplayer!: DailymotionPlayerComponent;

ngAfterViewInit() {
this.dmplayer.playVideo('x2yhuhb');
}
}
运行应用程序:
npm start -- --open
我在控制台中收到以下异常,表明我放在库代码中的类型引用已以错误的方式重新映射。
Error: node_modules/@mintplayer/ng-dailymotion-player/lib/components/dailymotion-player/dailymotion-player.component.d.ts:1:23 - error TS2688: Cannot find type definition file for 'projects/mintplayer/ng-dailymotion-player/src/typings'.

1 /// <reference types="projects/mintplayer/ng-dailymotion-player/src/typings" />
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Error: node_modules/@mintplayer/ng-dailymotion-player/lib/components/dailymotion-player/dailymotion-player.component.d.ts:23:31 - error TS2503: Cannot find namespace
'DM'.

23 stateChange: EventEmitter<DM.PlayerState>;
~~
为什么会这样?我需要更改哪些库才能在其他项目中工作?
编辑 1
我已经能够创建一个 similar package for the Youtube player ,它工作正常并使用 @types/youtube .但是由于 DailyMotion 没有类型,我希望它们在同一个项目/存储库中定义。
编辑 2
  • 这是 version 1.1.0
  • State of the repository for this version

  • DailymotionPlayerComponent包含以下类型引用:
    /// <reference path="../../../types/dailymotion.d.ts" />
    Angular 编译器将其转换为:
    /// <reference types="projects/mintplayer/ng-dailymotion-player/src/types/dailymotion" />
    导致使用此库的项目构建失败。

    最佳答案

    我在尝试构建 Angular 库时没有导出的类型也有类似的问题。
    您可以尝试更改 daylimotion.d.tsdaylimotion.interface.ts ?
    然后不要忘记将引用添加到您的 public-api.ts 中文件如下

    export * from './lib/dailymotion.interface.ts'
    遗憾的是,我无法解释为什么 angular 库无法导出 d.ts文件,但对我来说这是解决方法。

    关于angular - 使用自己的类型发布 angular 包 - 类型引用包含错误的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68009011/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com