From cea9d7b13ce0afd5424a96ef853d62c2a131085d Mon Sep 17 00:00:00 2001 From: younggglcy Date: Thu, 25 Apr 2024 03:16:25 +0800 Subject: [PATCH 1/2] feat: explicitly declare the return type for methods return `modify.call()` --- packages/quill/src/core/quill.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/quill/src/core/quill.ts b/packages/quill/src/core/quill.ts index 2bfc29c00b..94787ecf84 100644 --- a/packages/quill/src/core/quill.ts +++ b/packages/quill/src/core/quill.ts @@ -334,7 +334,7 @@ class Quill { name: string, value: unknown, source: EmitterSource = Emitter.sources.API, - ) { + ): Delta { return modify.call( this, () => { @@ -557,7 +557,7 @@ class Quill { embed: string, value: unknown, source: EmitterSource = Quill.sources.API, - ) { + ): Delta { return modify.call( this, () => { @@ -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, @@ -688,7 +688,7 @@ class Quill { setContents( delta: Delta | Op[], source: EmitterSource = Emitter.sources.API, - ) { + ): Delta { return modify.call( this, () => { @@ -741,7 +741,7 @@ class Quill { updateContents( delta: Delta | Op[], source: EmitterSource = Emitter.sources.API, - ) { + ): Delta { return modify.call( this, () => { From aac6fbc5c029dd223d80f5cb9ae7253b2135fedc Mon Sep 17 00:00:00 2001 From: younggglcy Date: Thu, 25 Apr 2024 23:23:54 +0800 Subject: [PATCH 2/2] test: assert delta --- packages/quill/test/types/quill.test-d.ts | 36 ++++++++++++++--------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/packages/quill/test/types/quill.test-d.ts b/packages/quill/test/types/quill.test-d.ts index 1d65de3823..004180a87d 100644 --- a/packages/quill/test/types/quill.test-d.ts +++ b/packages/quill/test/types/quill.test-d.ts @@ -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( + quill.insertEmbed(10, 'image', 'https://example.com/logo.png'), + ); + assertType( + quill.insertEmbed(10, 'image', 'https://example.com/logo.png', 'api'), + ); } { @@ -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(quill.updateContents([{ insert: 'Hello World!' }])); + assertType(quill.updateContents([{ insert: 'Hello World!' }], 'api')); + assertType(quill.updateContents(new Delta().insert('Hello World!'))); + assertType( + 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(quill.setContents([{ insert: 'Hello World!\n' }])); + assertType(quill.setContents([{ insert: 'Hello World!\n' }], 'api')); + assertType(quill.setContents(new Delta().insert('Hello World!\n'))); + assertType( + quill.setContents(new Delta().insert('Hello World!\n'), 'api'), + ); } { - quill.format('bold', true); - quill.format('bold', true, 'api'); + assertType(quill.format('bold', true)); + assertType(quill.format('bold', true, 'api')); } { @@ -136,8 +144,8 @@ const quill = new Quill('#editor'); } { - quill.removeFormat(3, 2); - quill.removeFormat(3, 2, 'user'); + assertType(quill.removeFormat(3, 2)); + assertType(quill.removeFormat(3, 2, 'user')); } {