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

Add generics to OutputBlockData #1326

Merged

Conversation

hata6502
Copy link
Contributor

@hata6502 hata6502 commented Sep 24, 2020

@hata6502 hata6502 force-pushed the feature/add-generic-output-block-data branch from cb7a1e2 to ec19f8b Compare October 10, 2020 03:31
@khaydarov khaydarov changed the base branch from next to master October 14, 2020 11:59
@hata6502 hata6502 force-pushed the feature/add-generic-output-block-data branch from ec19f8b to 8b0e2c1 Compare October 15, 2020 14:20
@hata6502 hata6502 force-pushed the feature/add-generic-output-block-data branch from 8b0e2c1 to 8e31a5b Compare November 21, 2020 08:30
@hata6502 hata6502 changed the base branch from master to next November 21, 2020 08:31
@hata6502
Copy link
Contributor Author

I create a repository to introduce the better way to use Editor.js with TypeScript.
Please see: https://github.com/hata6502/editorjs-examples/blob/main/examples/EditorJSData.ts

*/
type: string;
type: S;
Copy link
Member

Choose a reason for hiding this comment

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

The type is always a string. Are you sure we need a generic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By using Generics, Editor.js users can describe string literal types.

https://www.typescriptlang.org/docs/handbook/literal-types.html#string-literal-types

By using string literal types in OutputBlockData['type'], Editor.js users can describe more type-safe OutputData in each application.

See also:
https://github.com/hata6502/editorjs-examples/blob/main/examples/ExampleEditorJSData.ts#L17

@@ -3,15 +3,15 @@ import {BlockToolData} from '../tools';
/**
* Output of one Tool
*/
export interface OutputBlockData {
export interface OutputBlockData<S extends string = string, T extends object = any> {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export interface OutputBlockData<S extends string = string, T extends object = any> {
export interface OutputBlockData<S extends string = string, Data extends object = any> {

Copy link
Member

Choose a reason for hiding this comment

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

and describe it via @template please

@hata6502 hata6502 force-pushed the feature/add-generic-output-block-data branch from 5a895e0 to 85d1dac Compare February 20, 2021 02:27
@hata6502 hata6502 force-pushed the feature/add-generic-output-block-data branch from 85d1dac to 602bfcf Compare February 20, 2021 02:29
@hata6502 hata6502 requested a review from neSpecc February 20, 2021 02:29
@gohabereg gohabereg merged commit 3bf30f0 into codex-team:next Feb 27, 2021
@hata6502 hata6502 deleted the feature/add-generic-output-block-data branch February 28, 2021 00:31
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.

4 participants