找不到角度航点打字稿错误模块 [英] angular waypoints typescript error module not found

查看:73
本文介绍了找不到角度航点打字稿错误模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用npm install waypoints安装了Waypoints库,并使用

添加了类型

npm install-保存@ types/waypoints .

我收到错误/node_modules/@types/waypoints/index.d.ts'不是模块.

在Angular 4应用程序中使用waypoints.js

讨论了相同的问题.用户有相同的错误.有一条评论建议使用export package_name = package_name.这应该有用",我不知道如何实现.

我尝试添加

  export =航点导出为名称空间航路点;声明名称空间航路点{}从航路点"导入*作为航路点; 

当我尝试导入航路点时,没有任何错误.但是,如果我再添加一个这样的航路点:

  let waypoint = new Waypoint.Waypoint({元素:document.querySelector(#p5"),处理程序:function(){},}); 

我遇到另一个错误->

未找到模块:错误:无法解析航路点"

解决方案

出口

  export =航点导出为名称空间航路点;声明名称空间航路点{} 

不能解决问题.无需更改@ types/waypoints中的任何内容,只需在需要的组件中添加 declare const Waypoint:any; .就像简单的例子一样

 声明const Waypoint:任何;//在此处声明Waypoint类以对其进行访问@零件({选择器:"my-comp",模板:< div id ="abc"> Abc</div>",})导出类MyComponent实现OnInit {ngOnInit(){令wp =新的Waypoint({元素:document.getElementById("abc"),处理程序:(方向)=>{如果(方向=='向下'){wp.​​element.classList.add("fadeInUp");wp.​​destroy();}},抵消:"95%"});}} 

这是解决组合错误的方法.我们知道一旦应用程序运行,就会出现 Waypoint ,因此只需声明类型为 any Waypoint 类即可解决问题.

I installed the waypoints library with npm install waypoints and added types with

npm install --save @types/waypoints.

I get the error /node_modules/@types/waypoints/index.d.ts' is not a module.

Using waypoints.js in Angular 4 application

discuses the same problem. The user had the same error. One comment suggests "Use export package_name = package_name. this should work" I didn't know how to implement that.

I tried to add

export = waypoints
export as namespace waypoints;
declare namespace waypoints { 

}

import * as Waypoint from 'waypoints';

When I then try to import the waypoint I get no error. But if I then add a waypoint like this:

let waypoint = new Waypoint.Waypoint({
  element: document.querySelector("#p5"),
  handler: function () {

  },
});

I get another error ->

Module not found: Error: Can't resolve 'waypoints'

解决方案

The exports

export = waypoints
export as namespace waypoints;
declare namespace waypoints { 

}

will not solve the problem. Don't change anything in @types/waypoints, just add declare const Waypoint: any; to the component where you need it. Like simple example

declare const Waypoint: any; // Declare the Waypoint class here to access it

@Component({
  selector: 'my-comp',
  template: '<div id="abc">Abc</div>',
})
export class MyComponent implements OnInit {
  ngOnInit() {
    let wp = new Waypoint({
      element: document.getElementById("abc"),
      handler: (direction) => {
        if (direction == 'down') {
          wp.element.classList.add("fadeInUp");
          wp.destroy();
        }
      },
      offset: '95%'
    });
  }
}

This is solve the complation error(s). As we know that Waypoint will be present once the app is running so just declaring Waypoint class as of type any would do the trick.

这篇关于找不到角度航点打字稿错误模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆