Skip to content

Commit

Permalink
Remove unnecessary expect error directives
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 22, 2022
1 parent b4baafd commit b5176b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 39 deletions.
29 changes: 12 additions & 17 deletions blots/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import {
Registry,
} from 'parchment';
import { Blot, Parent } from 'parchment/dist/typings/blot/abstract/blot';
import Delta from 'quill-delta';
import Emitter, { EmitterSource } from '../core/emitter';
import Block, { BlockEmbed } from './block';
import Break from './break';
import Container from './container';

function isLine(blot: Blot): blot is Block | BlockEmbed {
function isLine(blot: unknown): blot is Block | BlockEmbed {
return blot instanceof Block || blot instanceof BlockEmbed;
}

interface UpdatableEmbed {
updateContent(change: Delta): void;
updateContent(change: unknown): void;
}

function isUpdatable(blot: Blot): blot is Blot & UpdatableEmbed {
Expand Down Expand Up @@ -123,12 +122,11 @@ class Scroll extends ScrollBlot {
this.optimize();
}

insertBefore(blot, ref) {
insertBefore(blot: Blot, ref?: Blot) {
if (blot.statics.scope === Scope.INLINE_BLOT) {
// @ts-expect-error Currently the type is not enforced
const wrapper: Parent = this.scroll.create(
const wrapper = this.scroll.create(
this.statics.defaultChild.blotName,
);
) as Parent;
wrapper.appendChild(blot);
super.insertBefore(wrapper, ref);
} else {
Expand All @@ -140,17 +138,14 @@ class Scroll extends ScrollBlot {
return this.domNode.getAttribute('contenteditable') === 'true';
}

leaf(index: number): [LeafBlot, number] | [null, -1] {
leaf(index: number): [LeafBlot | null, number] {
const last = this.path(index).pop();
if (!last) {
return [null, -1];
}

const [blot, offset] = last;
if (!(blot instanceof LeafBlot)) {
return [null, -1];
}
return [blot, offset];
return blot instanceof LeafBlot ? [blot, offset] : [null, -1];
}

line(index: number): [Block | BlockEmbed | null, number] {
Expand Down Expand Up @@ -194,17 +189,17 @@ class Scroll extends ScrollBlot {
}
}

path(index) {
path(index: number) {
return super.path(index).slice(1); // Exclude self
}

remove() {
// Never remove self
}

update(source?: EmitterSource);
update(mutations?: MutationRecord[]);
update(mutations?: MutationRecord[] | EmitterSource) {
update(source?: EmitterSource): void;
update(mutations?: MutationRecord[]): void;
update(mutations?: MutationRecord[] | EmitterSource): void {
if (this.batch) {
if (Array.isArray(mutations)) {
this.batch = this.batch.concat(mutations);
Expand All @@ -231,7 +226,7 @@ class Scroll extends ScrollBlot {
}
}

updateEmbedAt(index, key, change) {
updateEmbedAt(index: number, key: string, change: unknown) {
// Currently it only supports top-level embeds (BlockEmbed).
// We can update `ParentBlot` in parchment to support inline embeds.
const [blot] = this.descendant(b => b instanceof BlockEmbed, index);
Expand Down
6 changes: 3 additions & 3 deletions core/quill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ class Quill {
this.root.classList.add('ql-blank');
this.scrollingContainer = this.options.scrollingContainer || this.root;
this.emitter = new Emitter();
// @ts-expect-error
const ScrollBlot: ScrollConstructor = this.options.registry.query(
// @ts-expect-error TODO: fix BlotConstructor
const ScrollBlot = this.options.registry.query(
Parchment.ScrollBlot.blotName,
);
) as ScrollConstructor;
this.scroll = new ScrollBlot(this.options.registry, this.root, {
emitter: this.emitter,
});
Expand Down
43 changes: 24 additions & 19 deletions formats/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class TableCell extends Block {
return undefined;
}

next: this | null;

cellOffset() {
if (this.parent) {
return this.parent.children.indexOf(this);
Expand Down Expand Up @@ -56,15 +58,17 @@ class TableCell extends Block {
}

class TableRow extends Container {
static blotName = 'table-row';
static tagName = 'TR';

children: LinkedList<TableCell>;
next: this | null;

checkMerge() {
if (super.checkMerge() && this.next.children.head != null) {
// @ts-expect-error all children are table cells
const thisHead = this.children.head.formats();
// @ts-expect-error all children are table cells
const thisTail = this.children.tail.formats();
// @ts-expect-error all children are table cells
const nextHead = this.next.children.head.formats();
// @ts-expect-error all children are table cells
const nextTail = this.next.children.tail.formats();
return (
thisHead.table === thisTail.table &&
Expand All @@ -78,10 +82,9 @@ class TableRow extends Container {
optimize(...args) {
// @ts-expect-error
super.optimize(...args);
(this.children as LinkedList<TableCell>).forEach(child => {
this.children.forEach(child => {
if (child.next == null) return;
const childFormats = child.formats();
// @ts-expect-error
const nextFormats = child.next.formats();
if (childFormats.table !== nextFormats.table) {
const next = this.splitAfter(child);
Expand Down Expand Up @@ -109,14 +112,20 @@ class TableRow extends Container {
return this.parent && this.parent.parent;
}
}
TableRow.blotName = 'table-row';
TableRow.tagName = 'TR';

class TableBody extends Container {}
TableBody.blotName = 'table-body';
TableBody.tagName = 'TBODY';
class TableBody extends Container {
static blotName = 'table-body';
static tagName = 'TBODY';

children: LinkedList<TableRow>;
}

class TableContainer extends Container {
static blotName = 'table-container';
static tagName = 'TABLE';

children: LinkedList<TableBody>;

balanceCells() {
// @ts-expect-error TODO: fix signature of ParentBlot.descendants
const rows = this.descendants(TableRow) as TableRow[];
Expand All @@ -137,16 +146,16 @@ class TableContainer extends Container {
});
}

cells(column) {
cells(column: number) {
return this.rows().map(row => row.children.at(column));
}

deleteColumn(index) {
deleteColumn(index: number) {
// @ts-expect-error
const [body] = this.descendant(TableBody) as TableBody[];
if (body == null || body.children.head == null) return;
body.children.forEach(row => {
const cell = (row as TableRow).children.at(index);
const cell = row.children.at(index);
if (cell != null) {
cell.remove();
}
Expand All @@ -157,7 +166,7 @@ class TableContainer extends Container {
// @ts-expect-error
const [body] = this.descendant(TableBody) as TableBody[];
if (body == null || body.children.head == null) return;
(body.children as LinkedList<TableRow>).forEach(row => {
body.children.forEach(row => {
const ref = row.children.at(index);
const value = TableCell.formats(row.children.head.domNode);
const cell = this.scroll.create(TableCell.blotName, value);
Expand All @@ -171,7 +180,6 @@ class TableContainer extends Container {
if (body == null || body.children.head == null) return;
const id = tableId();
const row = this.scroll.create(TableRow.blotName) as TableRow;
// @ts-expect-error
body.children.head.children.forEach(() => {
const cell = this.scroll.create(TableCell.blotName, id);
row.appendChild(cell);
Expand All @@ -183,12 +191,9 @@ class TableContainer extends Container {
rows() {
const body = this.children.head;
if (body == null) return [];
// @ts-expect-error
return body.children.map(row => row);
}
}
TableContainer.blotName = 'table-container';
TableContainer.tagName = 'TABLE';

TableContainer.allowedChildren = [TableBody];
TableBody.requiredContainer = TableContainer;
Expand Down

0 comments on commit b5176b5

Please sign in to comment.