Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(types): tools export types added #2802

Merged
merged 15 commits into from
Aug 9, 2024
Merged

fix(types): tools export types added #2802

merged 15 commits into from
Aug 9, 2024

Conversation

neSpecc
Copy link
Member

@neSpecc neSpecc commented Aug 3, 2024

Problem

Some compilers can't build projects with current editor.js import because of errors like that

node_modules/.pnpm/@[email protected]/node_modules/@editorjs/editorjs/types/api/tools.d.ts:1:22:
  1 │ import BlockTool from "../../src/components/tools/block";

Resolves #2771

Cause

In #2718 we introduced api.tool.getBlockTools() method that returns BlockTool[] objects which declared under the npmignored /src folder.

Solution

Confusing names

We have a confusing names in src/components/tools/:

  • BlockTool — it is not a block tool (see types/tools/block-tool.d.ts). It is more like block tool adapater
  • same with InlineTool and BlockTune

So I've renamed them to BlockToolAdapter, InlineToolAdapter, BlockTuneAdapter across all the code.

Now BlockTool has only one meaning declared in types/tools/block-tool.d.ts

Types for adapters

I've manually created types for adapters:

/types/tools/adapters/block-tool-adapter.d.ts
/types/tools/adapters/inline-tool-adapter.d.ts
/types/tools/adapters/block-tune-adapter.d.ts

Classes in src/components/tools/ implements those adapters interfaces.

Also

  • Enums are moved to /types as well, but under .ts files instead of d.ts (complier can't find enums values in d.ts)
  • Popover types are moved to /types as well
  • Added @/types alias
  • Eslint now enforces to use "import type" when only type is needed.

We manually maintain /types which may be not-best solution today. We can consider autogenerating types in a future.

@neSpecc neSpecc changed the title fix(type): tools export types added fix(types): tools export types added Aug 3, 2024
src/components/block/index.ts Show resolved Hide resolved
src/components/tools/base.ts Outdated Show resolved Hide resolved
@neSpecc neSpecc merged commit 3d01be4 into next Aug 9, 2024
6 checks passed
@neSpecc neSpecc deleted the fix-types branch August 9, 2024 15:05
@golodnoy
Copy link

HI @neSpecc
There are still bugs in the new version of the library. Please fix them
2024-08-12 09 46 45

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type error, type files are missing while compiling
5 participants