BotBuilder-MicrosoftTeams-node
BotBuilder-MicrosoftTeams-node copied to clipboard
TeamsContext.team possibly undefined
Current typing is
// teamsContext.ts
export class TeamsContext {
public get team(): models.TeamInfo {
return this.getTeamsChannelData().team;
}
}
// schema/models/index.ts
export interface TeamInfo {
id?: string;
name?: string;
}
The following code compiles correctly, but fails at runtime with a TypeError if called outside the context of a team (direct message)
// teamsCtx.team.id is undefined | string
if (teamsCtx.team.id) {
// teamsCtx.team.id is type string
console.log(teamsCtx.team.id)
}
TypeError: Cannot read property `id` of undefined
Suggested fix:
- make team an optional property of class TeamsContext:
public get team(): models.TeamInfo | undefined
- infer return type from getTeamsChannelData.team;
public get team() {
(no return annotation)