Vue3 + G6 Trampling notes 2 (.d.ts Type Declaration file)

Today we learned about g6-editor flowchart guide package when editing framework

import G6Editor from "@antv/g6-editor";
Copy the code

Such an error occurs

Unable to find declaration file for module '@antv/g6-editor'. "C: / Users/Lenovo/Desktop/vue/myvue3 / node_modules / @ antv/g6 - editor/build/g6Editor js" implicit "any" type. Try using 'NPM I -- save-dev@types /antv__g6-editor' (if present), or add a declare Module '@antv/g6-editor'; New declaration of '(.d.ts) file TS (7016)Copy the code

Try using NPM I — save-dev@types /antv__g6-editor

The third party library does not have a t.d. ts declaration file when using Typescript, so it cannot be used in the current project. If we want to use these libraries smoothly, we may need to add declaration files.

The solution

Create a new types directory under the SRC directory, then create an index.d.ts file under the types directory and add the code Declare Module “Third Party library name” to the file.

declare module '@antv/g6-editor';
Copy the code

It’s ready to run.