我在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");
}
});
});
由于没有其他类型传递类型参数,ConversationState
必须没有类型参数,因此错误。
new ConversationState<ConfState>
// should be changed to
new ConversationState
删除通用。对库的更新不再需要ConversationState来获取泛型。
而是使用这个:
let conversationState;
const memoryStorage = new MemoryStorage();
conversationState = new ConversationState(memoryStorage);