Angular for SQL提示上的Codemirror起作用,但给出类型脚本键入错误
突击检查: 我正在尝试在Angular 10中为SQL提示实现CodeMirror,如下所示:。该功能在网页上正常工作,我还可以在控制台日志中看到正确的选项。但是,我也看到此错误Angular for SQL提示上的Codemirror起作用,但给出类型脚本键入错误,sql,angular,typescript,typescript-typings,codemirror,Sql,Angular,Typescript,Typescript Typings,Codemirror,突击检查: 我正在尝试在Angular 10中为SQL提示实现CodeMirror,如下所示:。该功能在网页上正常工作,我还可以在控制台日志中看到正确的选项。但是,我也看到此错误无法分配给类型“ShowHintOptions”,因为我错误地设置了hintOptions选项。我还没有找到任何其他的例子,而且我尝试按照正确的输入法进行操作都没有成功。请帮忙 装置 npm安装codemirror@types/codemirror 代码 已找到解决错误的方法 添加任何类型的变量以保存值 const op
无法分配给类型“ShowHintOptions”
,因为我错误地设置了hintOptions
选项。我还没有找到任何其他的例子,而且我尝试按照正确的输入法进行操作都没有成功。请帮忙
装置
npm安装codemirror@types/codemirror
代码
已找到解决错误的方法 添加任何类型的变量以保存值
const options: any = {
tables: {
users: ["name", "score", "birthDate"],
countries: ["name", "population", "size"]
}
};
将变量强制转换为ShowHintOptions
hintOptions:选项为codemirror.ShowHintOptions,
新代码
ngOnInit(): void {
const options: any = {
tables: {
users: ["name", "score", "birthDate"],
countries: ["name", "population", "size"]
}
};
this.editor = codemirror.fromTextArea(this.ref.nativeElement, {
mode: "text/x-mysql",
hintOptions: options as codemirror.ShowHintOptions,
extraKeys: { "Ctrl-Space": "autocomplete" }
});
console.log(this.editor.getOption('hintOptions'));
}
库中的定义显示了可以传递的字段。要么你把未知的东西传递给图书馆,要么它的打字错误wrong@Andrei我已经读过了,但仍然坚持尝试正确的无错误实现。
const options: any = {
tables: {
users: ["name", "score", "birthDate"],
countries: ["name", "population", "size"]
}
};
ngOnInit(): void {
const options: any = {
tables: {
users: ["name", "score", "birthDate"],
countries: ["name", "population", "size"]
}
};
this.editor = codemirror.fromTextArea(this.ref.nativeElement, {
mode: "text/x-mysql",
hintOptions: options as codemirror.ShowHintOptions,
extraKeys: { "Ctrl-Space": "autocomplete" }
});
console.log(this.editor.getOption('hintOptions'));
}