Skip to content

Conversation

@amriksingh0786
Copy link

@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
* Build styles
*/
import './index.css';
import "./index.css";
Copy link
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
Contributor

Choose a reason for hiding this comment

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

still actual

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
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

src/index.ts Outdated
}

export default class SimpleImage {
private api: any;
Copy link
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

src/index.ts Outdated
data: string;
}

export default class SimpleImage {
Copy link
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

src/index.ts Outdated
*/
constructor({ data, config, api, readOnly }) {
constructor({
data = {} as Partial<SimpleImageData>,
Copy link
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
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
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

return Object.assign(this.data, {
url: image.src,
caption: caption.innerHTML,
url: image?.src || "",
Copy link
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 on lines +443 to +446
if (!this.nodes.imageHolder) return;

this.tunes.forEach((tune) => {
this.nodes.imageHolder?.classList.toggle(
Copy link
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 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

lack of jsdoc

tsconfig.json Outdated
"module": "ESNext",
"moduleResolution": "node",
"strict": true,
"jsx": "preserve",
Copy link
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

package.json Outdated
"scripts": {
"dev": "vite",
"build": "vite build"
"build": "tsc && vite build"
Copy link
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

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
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?

* Build styles
*/
import './index.css';
import "./index.css";
Copy link
Contributor

Choose a reason for hiding this comment

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

still actual

src/index.ts Outdated
*/
constructor({ data, config, api, readOnly }) {
constructor({
data = {} as Partial<SimpleImageData>,
Copy link
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

@@ -0,0 +1,20 @@
import type { API } from '@editorjs/editorjs';

export interface SimpleImageData {
Copy link
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