Forum Discussion
sharepoint type script in SPFX
Hi All,
I am working in SPFX with angular 2. I wanted to use sharepoint type script in my project. I have installed the sharepoint type script with npm command "typings install dt~sharepoint --global --save". When i tried to build the project with gulp serve command it give me 43 error all are in sharepoint dt.The error is "Error - typescript - typings\globals\sharepoint\index.d.ts(11190,40): error TS2304: Cannot find name 'Sys'." It seems some depency is not installed but i could not able to figure out which one. Please share your knowledge with me to fix this problem.
i want to use the sharepoint global variable _spPageContextInfo in typescript fir this reason i need sharepoint typescript reference that i get by "typings install dt~sharepoint --global --save". when try to build the project with gulf server it gives me avove error.
- Sorry, I was wrong about using _spPageContextInfo. it's possible to use it on spfx (I think the issue I remember is when using the Local workbench)
This sample
https://github.com/SharePoint/sp-dev-fx-webparts/blob/98138de57fd8ba3eb19afa69caf032ab785f0b0e/samples/react-search/src/webparts/searchSpfx/flux/helpers/SearchTokenHelper.ts
is using that variable, but I don't see the sharepoint typings. Instead, it's creating a custom interface with all _spPageContextInfo properties, and declaring the variable as:
declare const _spPageContextInfo: IPageContext;
Where IPageContext is a custom interface defined here:
https://github.com/SharePoint/sp-dev-fx-webparts/blob/98138de57fd8ba3eb19afa69caf032ab785f0b0e/samples/react-search/src/webparts/searchSpfx/utils/IPageContext.ts This looks like an issue with the typings being out of sync. As a first step I suggest that you make sure you have the latest generator installed and create a new project and see if that builds properly. The scaffolded project will include TypeScript.
Angular 2 (aka Angular) is not yet fully supported in SPFx, but there is a prototype sample at https://github.com/SharePoint/sp-dev-fx-webparts/tree/master/samples/angular2-prototype.
- couple of comments:
- in order to install typings, you should use npm instead of Typings:
npm install @types/sharepoint --save-dev
- Sys is not a sharepoint type. I think it comes from Microsoft AJAX.
- not sure if a spfx webpart can access the _spPageContextInfo variable (I remember @PatrickRodgers had some issues with the PnP JS library because the spPageContextInfo variable was not available on the spfx).
- why do you need that spPageContextInfo variable? I'm asking cos you have some "context" info in the spfx webpart:
this.context.pageContext