Skip to content

Commit

Permalink
Improve typings for methods that return a Delta (#4136)
Browse files Browse the repository at this point in the history
  • Loading branch information
younggglcy authored Apr 30, 2024
1 parent 6590aa4 commit dbaa1e0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
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

0 comments on commit dbaa1e0

Please sign in to comment.