Skip to content

Migrate to TypeScript and update project configuration, issue #72#76

Open
amriksingh0786 wants to merge 3 commits intoeditor-js:masterfrom
amriksingh0786:master
Open

Migrate to TypeScript and update project configuration, issue #72#76
amriksingh0786 wants to merge 3 commits intoeditor-js:masterfrom
amriksingh0786:master

Conversation

@amriksingh0786
Copy link
Copy Markdown

@amriksingh0786 amriksingh0786 commented Feb 17, 2025

Migrate to TypeScript and update project configuration #76

@amriksingh0786 amriksingh0786 changed the title Migrate to TypeScript and update project configuration Migrate to TypeScript and update project configuration, issue #72 Feb 17, 2025
Comment thread src/index.ts
* Build styles
*/
import './index.css';
import "./index.css";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, use single quotes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual

Comment thread src/index.ts Outdated
Comment on lines +28 to +42
// Add these interfaces at the top of the file
interface HTMLPasteEventDetail {
type: "html";
data: HTMLElement;
}

interface FilePasteEventDetail {
type: "file";
file: File;
}

interface PatternPasteEventDetail {
type: "pattern";
data: string;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these interfaces are redundant since editor.js package already includes these types

Comment thread src/index.ts Outdated
}

export default class SimpleImage {
private api: any;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specify exact type instead of any

Comment thread src/index.ts Outdated
data: string;
}

export default class SimpleImage {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

class should implement BlockTool

Comment thread src/index.ts
Comment thread src/index.ts Outdated
*/
constructor({ data, config, api, readOnly }) {
constructor({
data = {} as Partial<SimpleImageData>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is the logic change, please, explain it

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change improves type safety by:

  1. Ensuring data is always an object (defaulting to empty object if not provided)
  2. Explicitly marking data as a partial version of SimpleImageData type, meaning not all properties are required

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually data can't be an empty object. As well and partial

Comment thread src/index.ts
return Object.assign(this.data, {
url: image.src,
caption: caption.innerHTML,
url: image?.src || "",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image and caption cant be undefined, so this logic never be used

Comment thread src/index.ts
Comment on lines +443 to +446
if (!this.nodes.imageHolder) return;

this.tunes.forEach((tune) => {
this.nodes.imageHolder?.classList.toggle(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems strange that you check for undefined and then use ?

Comment thread src/types.ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lack of jsdoc

Comment thread tsconfig.json Outdated
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check carefully every option you're added, it should have particular meaning for this project

Comment thread package.json Outdated
"scripts": {
"dev": "vite",
"build": "vite build"
"build": "tsc && vite build"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have both tsc and vite for compiling? For declarations generation we can use vite-plugin-dts like in Image Tool
https://github.com/editor-js/image/blob/master/vite.config.js

Comment thread package.json Outdated
Comment on lines +36 to +38
"@types/dompurify": "^3.0.5",
"@types/node": "^22.13.4",
"@vitejs/plugin-react": "^4.3.4",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why they are used?

Comment thread src/index.ts
* Build styles
*/
import './index.css';
import "./index.css";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

still actual

Comment thread src/index.ts Outdated
*/
constructor({ data, config, api, readOnly }) {
constructor({
data = {} as Partial<SimpleImageData>,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually data can't be an empty object. As well and partial

Comment thread src/types.ts
@@ -0,0 +1,20 @@
import type { API } from '@editorjs/editorjs';

export interface SimpleImageData {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsdocs missed

@amriksingh0786 amriksingh0786 requested a review from neSpecc March 19, 2025 11:19
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.

2 participants