Update to _spPageContextInfo type definitions - new properties available

Jun 16, 2017

If you’re building modern SharePoint components (Framework or not), there’s a high chance you’re using TypeScript.

In that case you’re probably using @types/SharePoint to provide auto-completion as well as some level of understanding for the compiler of what’s going on.

There’s one object in particular that SharePoint hydrates for us to give some understanding of where the user is and what he/she is doing: _spPageContextInfo.

A lot of properties were missing in those type definitions, old stuff like the web Id but also new things coming from SharePoint Online like canUserCreateMicrosoftForm.

A few days ago I created a pull request to add these properties so you don’t need anymore to do things like (_spPageContextInfo as any).webId for compilation to go through and it recently got accepted.

The entire list of new properties is here https://github.com/DefinitelyTyped/DefinitelyTyped/pull/17089/commits/4f8942e318d76352cf0e2e9a68e72ba4b21cee55 and you can get those just by updating @types/SharePoint.

Happy coding!


Last edited Apr 15, 2024 by Vincent Biret


Tags: