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

Improve typings for methods that return a Delta #4136

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/quill/src/core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ class Quill {
name: string,
value: unknown,
source: EmitterSource = Emitter.sources.API,
) {
): Delta {
return modify.call(
this,
() => {
Expand Down Expand Up @@ -557,7 +557,7 @@ class Quill {
embed: string,
value: unknown,
source: EmitterSource = Quill.sources.API,
) {
): Delta {
return modify.call(
this,
() => {
Expand Down Expand Up @@ -647,7 +647,7 @@ class Quill {
return this.emitter.once(...args);
}

removeFormat(index: number, length: number, source?: EmitterSource) {
removeFormat(index: number, length: number, source?: EmitterSource): Delta {
[index, length, , source] = overload(index, length, source);
return modify.call(
this,
Expand Down Expand Up @@ -688,7 +688,7 @@ class Quill {
setContents(
delta: Delta | Op[],
source: EmitterSource = Emitter.sources.API,
) {
): Delta {
return modify.call(
this,
() => {
Expand Down Expand Up @@ -741,7 +741,7 @@ class Quill {
updateContents(
delta: Delta | Op[],
source: EmitterSource = Emitter.sources.API,
) {
): Delta {
return modify.call(
this,
() => {
Expand Down
36 changes: 22 additions & 14 deletions packages/quill/test/types/quill.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ const quill = new Quill('#editor');
}

{
quill.insertEmbed(10, 'image', 'https://example.com/logo.png');
quill.insertEmbed(10, 'image', 'https://example.com/logo.png', 'api');
assertType<Delta>(
quill.insertEmbed(10, 'image', 'https://example.com/logo.png'),
);
assertType<Delta>(
quill.insertEmbed(10, 'image', 'https://example.com/logo.png', 'api'),
);
}

{
Expand Down Expand Up @@ -74,22 +78,26 @@ const quill = new Quill('#editor');
}

{
quill.updateContents([{ insert: 'Hello World!' }]);
quill.updateContents([{ insert: 'Hello World!' }], 'api');
quill.updateContents(new Delta().insert('Hello World!'));
quill.updateContents(new Delta().insert('Hello World!'), 'api');
assertType<Delta>(quill.updateContents([{ insert: 'Hello World!' }]));
assertType<Delta>(quill.updateContents([{ insert: 'Hello World!' }], 'api'));
assertType<Delta>(quill.updateContents(new Delta().insert('Hello World!')));
assertType<Delta>(
quill.updateContents(new Delta().insert('Hello World!'), 'api'),
);
}

{
quill.setContents([{ insert: 'Hello World!\n' }]);
quill.setContents([{ insert: 'Hello World!\n' }], 'api');
quill.setContents(new Delta().insert('Hello World!\n'));
quill.setContents(new Delta().insert('Hello World!\n'), 'api');
assertType<Delta>(quill.setContents([{ insert: 'Hello World!\n' }]));
assertType<Delta>(quill.setContents([{ insert: 'Hello World!\n' }], 'api'));
assertType<Delta>(quill.setContents(new Delta().insert('Hello World!\n')));
assertType<Delta>(
quill.setContents(new Delta().insert('Hello World!\n'), 'api'),
);
}

{
quill.format('bold', true);
quill.format('bold', true, 'api');
assertType<Delta>(quill.format('bold', true));
assertType<Delta>(quill.format('bold', true, 'api'));
}

{
Expand Down Expand Up @@ -136,8 +144,8 @@ const quill = new Quill('#editor');
}

{
quill.removeFormat(3, 2);
quill.removeFormat(3, 2, 'user');
assertType<Delta>(quill.removeFormat(3, 2));
assertType<Delta>(quill.removeFormat(3, 2, 'user'));
}

{
Expand Down
Loading