简体   繁体   English

Angular2 @ types / sharepoint / index.d.ts'不是模块

[英]Angular2 @types/sharepoint/index.d.ts' is not a module

I'm using Angular 2 in SharePoint 我在SharePoint中使用Angular 2

I'm building a service that needs to call Sharepoint via csom and rest and I have run into trouble with the typing for Sharepoint 2013 我正在构建一个需要通过csom和rest来调用Sharepoint的服务,而且我遇到了Sharepoint 2013的输入问题

I have run npm install @types/sharepoint --save-dev and am now trying to reference the sharepoint types in my TypeScript code 我已经运行了npm install @types/sharepoint --save-dev ,现在我尝试在我的TypeScript代码中引用sharepoint类型

when I import import * as sharepoint from 'sharepoint'; 当我import * as sharepoint from 'sharepoint';导入import * as sharepoint from 'sharepoint'; I get the error @types/sharepoint/index.d.ts' is not a module 我得到错误@types/sharepoint/index.d.ts' is not a module

I don't know how to fix this. 我不知道如何解决这个问题。

On a side note, doing the exact same thing with the D3 library throws no error ie 另外,对D3库执行完全相同的操作不会产生错误,即

npm install @types/d3 --save-dev

import * as d3 from 'd3';

works just fine 工作得很好

EDIT - 11 May 2018 编辑 - 2018年5月11日

At the top of your file add these to access any ambient variables 在文件的顶部添加这些以访问任何环境变量

declare var SP: any declare var _spPageContextInfo: any

You do not import typings. 你不进口打字。

If you can import from 'd3' without any compilation errors then your library folder must have a reference to 'd3' notably ./node_modules/d3 . 如果你可以从'd3'导入而没有任何编译错误,那么你的库文件夹必须引用'd3',特别是./node_modules/d3

Some Info on typings is that it guides the compiler as it generates JavaScript files. 关于打字的一些信息是指导编译器生成JavaScript文件。 Additionally, it gives you type checking at design which is a huge benefit to javascript. 此外,它为您提供了设计类型检查,这对javascript是一个巨大的好处。

you can check if there are modules for sharepoint Here is what i found : https://www.npmjs.com/browse/keyword/sharepoint 你可以检查是否有sharepoint的模块这是我找到的: https//www.npmjs.com/browse/keyword/sharepoint

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM