I believe this is a bug... as I can't find a mention of this in the release notes for 1.8.1.
In SPFx v1.8.1, when you create new SPFx project, you should be able to access the MSFT Teams context via this.context.microsoftTeams.... This worked in v1.8.0, but in 1.8.1, the microsoftTeams property is not defined.
Digging deeper, the BaseClientSideWebPart WebPartContext object appears to have changed from v1.8.0 => v1.8.1:
/*聽Excluded聽from聽this聽release聽type:聽microsoftTeams聽*/
Whereas in SPFx 1.8.0 it was:
readonly聽microsoftTeams?:聽typeof聽teamsJs;
This code triggers a build error in an SPFx v1.8.1 web part project:
protected onInit(): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (this.context.microsoftTeams) {
this.context.microsoftTeams.getContext(context => {
console.log('got teams context');
resolve();
});
} else {
resolve();
}
});
}
add the following code to the web part
protected onInit(): Promise<void> {
return new Promise<void>((resolve, reject) => {
if (this.context.microsoftTeams) {
this.context.microsoftTeams.getContext(context => {
console.log('teams context', context);
resolve();
});
} else {
resolve();
}
});
}
run gulp build & observe errors
Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.
So, bit of background. The public typings generation process went squirelly when we released 1.8.0, and it was fixed for 1.8.1. However, it looks like the microsoftTeams property didn't get moved from beta -> public, so when the typings cleanup process ran, it removed it from the public typings. For now, you can work around this by including the beta packages. We will fix this in the next drop. Thanks for the heads up.
Fixed with the 1.8.2 release, so closing this from here. Thanks for reporting this and sorry for the inconvenience caused by this regression.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues
Most helpful comment
So, bit of background. The public typings generation process went squirelly when we released 1.8.0, and it was fixed for 1.8.1. However, it looks like the microsoftTeams property didn't get moved from beta -> public, so when the typings cleanup process ran, it removed it from the public typings. For now, you can work around this by including the beta packages. We will fix this in the next drop. Thanks for the heads up.