我在type.ts中有一个ConfState接口,并且在app.ts中导入了ConfState接口,当我尝试使用它时,出现此错误。 预期有0个类型参数,但有1个。
** type.ts
export interface ConfState {
}
** app.ts
import {BotFrameworkAdapter,MemoryStorage,ConversationState} from "botbuilder";
import * as restify from "restify";
import {ConfState} from "./types";
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978,() => {
console.log("${server.name} listening on {server.url}");
});
const adapter = new BotFrameworkAdapter({
appId:process.env.MICROSOFT_APP_ID,
appPassword:process.env.MICROSOFT_APP_PASSWORD
});
const conversationState = new ConversationState<ConfState>(new MemoryStorage());
adapter.use(conversationState)
server.post("/api/message",(req, res) => {
adapter.processActivity(req,res, async (context) => {
if(context.activity.type === "message") {
const state = conversationState.get(context);
await context.sendActivity("You said ${context.activity.text}");
} else {
await context.sendActivity("${context.activity.type} event detected");
}
});
});
答案 0 :(得分:0)
由于没有其他类型要传递类型参数,
ConversationState
必须没有类型参数,因此会出现错误。
new ConversationState<ConfState>
// should be changed to
new ConversationState
答案 1 :(得分:0)
删除通用。对库的更新不再需要ConversationState来获取泛型。
而改用这个:
let conversationState;
const memoryStorage = new MemoryStorage();
conversationState = new ConversationState(memoryStorage);