Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit 30f96cb

Browse files
authored
Fix TS issues in JS samples (#4040)
* Add ts-check flag and fix issues (samples 2-7) * Add ts-check flag and fix issues (samples 8-17) * Add ts-check flag and fix issues (samples 18-24) * Add ts-check flag and fix issues (samples 40-47) * Add ts-check flag and fix issues (samples 48-49) * Add ts-check flag and fix issues (samples 84-86) * Add ts-check flag and fix issues (samples 80-83) * Add missing quote in comment. * Apply feedback
1 parent e15e9f8 commit 30f96cb

112 files changed

Lines changed: 425 additions & 120 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

samples/javascript_nodejs/02.echo-bot/bot.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
const { ActivityHandler, MessageFactory } = require('botbuilder');
57

68
class EchoBot extends ActivityHandler {
@@ -15,7 +17,7 @@ class EchoBot extends ActivityHandler {
1517
});
1618

1719
this.onMembersAdded(async (context, next) => {
18-
const membersAdded = context.activity.membersAdded;
20+
const membersAdded = context.activity.membersAdded ?? [];
1921
const welcomeText = 'Hello and welcome!';
2022
for (let cnt = 0; cnt < membersAdded.length; ++cnt) {
2123
if (membersAdded[cnt].id !== context.activity.recipient.id) {

samples/javascript_nodejs/02.echo-bot/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
const path = require('path');
57

68
const dotenv = require('dotenv');

samples/javascript_nodejs/03.welcome-users/bots/welcomeBot.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
// Import required Bot Framework classes.
57
const { ActionTypes, ActivityHandler, CardFactory } = require('botbuilder');
68

9+
/** @import { UserState } from 'botbuilder' */
10+
711
// Welcomed User property name
812
const WELCOMED_USER = 'welcomedUserProperty';
913

1014
class WelcomeBot extends ActivityHandler {
1115
/**
1216
*
13-
* @param {UserState} User state to persist boolean flag to indicate
17+
* @param {UserState} userState to persist boolean flag to indicate
1418
* if the bot had already welcomed the user
1519
*/
1620
constructor(userState) {

samples/javascript_nodejs/03.welcome-users/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
// Import required packages
57
const path = require('path');
68

samples/javascript_nodejs/05.multi-turn-prompt/bots/dialogBot.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
const { ActivityHandler } = require('botbuilder');
57

8+
/** @import { ConversationState, UserState } from 'botbuilder' */
9+
/** @import { UserProfileDialog } from '../dialogs/userProfileDialog' */
10+
611
class DialogBot extends ActivityHandler {
712
/**
813
*
914
* @param {ConversationState} conversationState
1015
* @param {UserState} userState
11-
* @param {Dialog} dialog
16+
* @param {UserProfileDialog} dialog
1217
*/
1318
constructor(conversationState, userState, dialog) {
1419
super();

samples/javascript_nodejs/05.multi-turn-prompt/dialogs/userProfileDialog.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
const { MessageFactory } = require('botbuilder');
57
const {
68
AttachmentPrompt,
@@ -112,7 +114,7 @@ class UserProfileDialog extends ComponentDialog {
112114
// We can send messages to the user at any point in the WaterfallStep.
113115
await step.context.sendActivity(msg);
114116

115-
if (step.context.activity.channelId === Channels.msteams) {
117+
if (step.context.activity.channelId === Channels.Msteams) {
116118
// This attachment prompt example is not designed to work for Teams attachments, so skip it in this case
117119
await step.context.sendActivity('Skipping attachment prompt in Teams channel...');
118120
return await step.next(undefined);

samples/javascript_nodejs/05.multi-turn-prompt/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
const restify = require('restify');
57
const path = require('path');
68

samples/javascript_nodejs/05.multi-turn-prompt/userProfile.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
class UserProfile {
57
constructor(transport, name, age, picture) {
68
this.transport = transport;

samples/javascript_nodejs/06.using-cards/bots/dialogBot.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
const { ActivityHandler } = require('botbuilder');
57

8+
/** @import { ConversationState, UserState } from 'botbuilder' */
9+
/** @import { MainDialog } from '../dialogs/mainDialog' */
10+
611
/**
712
* This IBot implementation can run any type of Dialog. The use of type parameterization is to allows multiple different bots
813
* to be run at different endpoints within the same project. This can be achieved by defining distinct Controller types
@@ -15,7 +20,7 @@ class DialogBot extends ActivityHandler {
1520
*
1621
* @param {ConversationState} conversationState
1722
* @param {UserState} userState
18-
* @param {Dialog} dialog
23+
* @param {MainDialog} dialog
1924
*/
2025
constructor(conversationState, userState, dialog) {
2126
super();

samples/javascript_nodejs/06.using-cards/bots/richCardsBot.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
// @ts-check
5+
46
const { MessageFactory } = require('botbuilder');
57
const { DialogBot } = require('./dialogBot');
68

@@ -13,7 +15,7 @@ class RichCardsBot extends DialogBot {
1315
super(conversationState, userState, dialog);
1416

1517
this.onMembersAdded(async (context, next) => {
16-
const membersAdded = context.activity.membersAdded;
18+
const membersAdded = context.activity.membersAdded ?? [];
1719
for (let cnt = 0; cnt < membersAdded.length; cnt++) {
1820
if (membersAdded[cnt].id !== context.activity.recipient.id) {
1921
const reply = MessageFactory.text('Welcome to CardBot. ' +

0 commit comments

Comments
 (0)