-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Add generics to OutputBlockData #1326
Conversation
cb7a1e2
to
ec19f8b
Compare
ec19f8b
to
8b0e2c1
Compare
8b0e2c1
to
8e31a5b
Compare
I create a repository to introduce the better way to use Editor.js with TypeScript. |
types/data-formats/output-data.d.ts
Outdated
*/ | ||
type: string; | ||
type: S; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
types/data-formats/output-data.d.ts
Outdated
@@ -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> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export interface OutputBlockData<S extends string = string, T extends object = any> { | |
export interface OutputBlockData<S extends string = string, Data extends object = any> { |
There was a problem hiding this comment.
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
5a895e0
to
85d1dac
Compare
85d1dac
to
602bfcf
Compare
#1551