如何使用第三方图书馆与TypeScript的前端



我最近开始学习和使用TypeScript,遇到了一个问题,我找不到满意的答案。希望有人能帮助我,并对此有所了解。我正在尝试使用一个名为Quill的wysiwyg编辑器,但没有用TypeScript编写的版本。经过一些研究,我发现了关于确定性类型,你可以使用类型定义来让TypeScript理解第三方库。我发现了这个,https://www.npmjs.com/package/@类型/套筒。这就是我被卡住的地方。如果我从node_modules导入文件,它解决了TypeScript中的问题,但JavaScript不喜欢这样,因为它不理解导入是什么,并给出以下错误:GEThttps://somerandomwebiste.com/node_modules/@types/quill/index.js net::ERR_ABORTED 404。我发现了一些有效的方法,但据我所知,这不是理想的解决方案,也不是应该如何做到的,意思是:

declare var Quill:any;

我的TS代码是:

import {Quill} from "../../../node_modules/@types/quill/index";
// declare  var Quill:any;
export class QuillSettings {
constructor() {
console.log("Quill settings4");
this.setQuill();
}
private setQuill(): void {
let container:HTMLElement = document.querySelector("#game-editor-container")!;
let quillOptions = {
debug: 'info',
modules: {
toolbar: [
['bold', 'italic'],
['link', 'blockquote', 'code-block', 'image'],
[{ list: 'ordered' }, { list: 'bullet' }]
]
},
placeholder: 'Compose an epic...',
readOnly: true,
theme: 'snow'
}
let quill:Quill = new Quill(container);
}
}

有人能帮我一下吗?

与其导入@types库,不如尝试导入常规库@types只提供typescript接口而不提供实际实现,@types由typescript本身自动使用。

你可以这样做:

import { Quill } from 'quill';

这应该只适用于typescript索引node_modules 中的所有包

最新更新