Skip to content

Commit

Permalink
refactor(editor): cleanup ts-expect-error (#9369)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saul-Mirone committed Dec 27, 2024
1 parent 908e3ef commit 2b27d62
Show file tree
Hide file tree
Showing 35 changed files with 84 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const insertLinkByQuickSearchCommand: Command<

// add normal link;
if ('externalUrl' in result) {
// @ts-expect-error TODO: fix after bookmark refactor
// @ts-expect-error FIXME: fix after bookmark refactor
std.command.exec('insertBookmark', { url: result.externalUrl });
return {
flavour: 'affine:bookmark',
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/block-image/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,15 +242,15 @@ export async function copyImageBlob(
}

try {
// @ts-expect-error FIXME: ts error
// @ts-expect-error FIXME: BS-2239
if (window.apis?.clipboard?.copyAsImageFromString) {
const dataURL = await convertToString(blob);
if (!dataURL)
throw new BlockSuiteError(
ErrorCode.DefaultRuntimeError,
'Cant convert a blob to data URL.'
);
// @ts-expect-error FIXME: ts error
// @ts-expect-error FIXME: BS-2239
await window.apis.clipboard?.copyAsImageFromString(dataURL);
} else {
// DOMException: Type image/jpeg not supported on write.
Expand Down
4 changes: 2 additions & 2 deletions blocksuite/affine/block-latex/src/latex-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class LatexBlockComponent extends CaptionedBlockComponent<LatexBlockModel
const latex = this.model.latex$.value;

katexContainer.replaceChildren();
// @ts-expect-error FIXME: ts error
// @ts-expect-error lit hack won't fix
delete katexContainer['_$litPart$'];

if (latex.length === 0) {
Expand All @@ -60,7 +60,7 @@ export class LatexBlockComponent extends CaptionedBlockComponent<LatexBlockModel
});
} catch {
katexContainer.replaceChildren();
// @ts-expect-error FIXME: ts error
// @ts-expect-error lit hack won't fix
delete katexContainer['_$litPart$'];
render(
html`<span class="latex-block-error-placeholder"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function forwardDelete(std: BlockStdScope) {
const ignoreForwardDeleteFlavourList: BlockSuite.Flavour[] = [
'affine:attachment',
'affine:bookmark',
// @ts-expect-error TODO: should be fixed after database model is migrated to affine-models
// @ts-expect-error FIXME: should be fixed after database model is migrated to affine-models
'affine:database',
'affine:code',
'affine:image',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
return true;
}

// @ts-expect-error TODO: should be fixed after database model is migrated to affine-models
// @ts-expect-error FIXME: should be fixed after database model is migrated to affine-models
if (matchFlavours(parent, ['affine:database'])) {
doc.deleteBlock(model);
focusTextModel(editorHost.std, prevBlock.id, prevBlock.text?.yText.length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export const LatexExtension = InlineMarkdownExtension({
if (!latexBlock || latexBlock.flavour !== 'affine:latex') return;

//FIXME(@Flrande): wait for refactor
// @ts-expect-error FIXME: ts error
// @ts-expect-error BS-2241
latexBlock.toggleEditor();
})
.catch(console.error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ export class AffineLatexNode extends SignalWatcher(
gap: 10px;
border-radius: 4px;
background: ${
// @ts-expect-error FIXME: ts error
unsafeCSSVarV2('label/red')
};
background: ${unsafeCSSVarV2('chip/label/red')};
color: ${unsafeCSSVarV2('text/highlight/fg/red')};
font-family: Inter;
Expand Down Expand Up @@ -126,7 +123,7 @@ export class AffineLatexNode extends SignalWatcher(
if (!latexContainer) return;

latexContainer.replaceChildren();
// @ts-expect-error FIXME: ts error
// @ts-expect-error lit hack won't fix
delete latexContainer['_$litPart$'];

if (latex.length === 0) {
Expand All @@ -142,7 +139,7 @@ export class AffineLatexNode extends SignalWatcher(
});
} catch {
latexContainer.replaceChildren();
// @ts-expect-error FIXME: ts error
// @ts-expect-error lit hack won't fix
delete latexContainer['_$litPart$'];
render(
html`<span class="error-placeholder">Error equation</span>`,
Expand Down
3 changes: 1 addition & 2 deletions blocksuite/affine/data-view/src/core/sort/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ const compareAny = (a: unknown, b: unknown) => {
if (!b) {
return Compare.LT;
}
// @ts-expect-error FIXME: ts error
return a - b;
return Number(a) - Number(b);
};

const compareTag = (type: DataTypeOf<typeof t.tag>, a: unknown, b: unknown) => {
Expand Down
7 changes: 3 additions & 4 deletions blocksuite/affine/model/src/elements/mindmap/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,10 +499,9 @@ export const mindmapStyleGetters: Record<MindmapStyle, MindmapStyleGetter> = {

export const applyNodeStyle = (node: MindmapNode, nodeStyle: NodeStyle) => {
Object.entries(nodeStyle).forEach(([key, value]) => {
// @ts-expect-error FIXME: ts error
if (!isEqual(node.element[key], value)) {
// @ts-expect-error FIXME: ts error
node.element[key] = value;
const element = node.element as unknown as Record<string, unknown>;
if (!isEqual(element[key], value)) {
element[key] = value;
}
});
};
4 changes: 2 additions & 2 deletions blocksuite/blocks/src/_common/transformers/middlewares.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ export const replaceIdMiddleware: JobMiddleware = ({ slots, collection }) => {
break;
}
case 'group': {
// @ts-expect-error FIXME: ts error
const json = value.children.json as Record<string, unknown>;
const json = (value.children as Record<string, unknown>)
.json as Record<string, unknown>;
Object.entries(json).forEach(([key, value]) => {
if (idMap.has(key)) {
delete json[key];
Expand Down
8 changes: 4 additions & 4 deletions blocksuite/blocks/src/code-block/adapters/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type BlockHtmlAdapterMatcher,
HastUtils,
} from '@blocksuite/affine-shared/adapters';
import type { DeltaInsert } from '@blocksuite/inline';
import { nanoid } from '@blocksuite/store';
import { bundledLanguagesInfo, codeToHast } from 'shiki';

Expand Down Expand Up @@ -74,16 +75,15 @@ export const codeBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher = {
)?.id ?? 'text')
: 'text';

// @ts-expect-error FIXME: ts error
const text = o.node.props.text.delta as DeltaInsert[];
const text = (o.node.props.text as Record<string, unknown>)
.delta as DeltaInsert[];
const code = text.map(delta => delta.insert).join('');
const hast = await codeToHast(code, {
lang: matchedLang,
theme: 'light-plus',
});

// @ts-expect-error FIXME: ts error
walkerContext.openNode(hast, 'children').closeNode();
walkerContext.openNode(hast as never, 'children').closeNode();
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function cloneDeep<T>(obj: T): T {
seen.set(val, copy);

Object.keys(val).forEach(key => {
// @ts-expect-error FIXME: ts error
// @ts-expect-error deep clone
copy[key] = clone(val[key]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ export class EdgelessChangeTextMenu extends WithDisposable(LitElement) {

const key = this.elementType === 'connector' ? 'labelStyle' : 'color';
this.elements.forEach(ele => {
// @ts-expect-error: FIXME
ele[event.type === 'start' ? 'stash' : 'pop'](key);
ele[event.type === 'start' ? 'stash' : 'pop'](key as 'color');
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const edgelessToBlob = async (
};

export const writeImageBlobToClipboard = async (blob: Blob) => {
// @ts-expect-error FIXME: ts error
// @ts-expect-error FIXME: BS-2239
if (window.apis?.clipboard?.copyAsImageFromString) {
// @ts-expect-error FIXME: ts error
// @ts-expect-error FIXME: BS-2239
await window.apis.clipboard?.copyAsImageFromString(blob);
} else {
await navigator.clipboard.write([new ClipboardItem({ [blob.type]: blob })]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export function setObjectPropMeta(
prop: string | symbol,
val: unknown
) {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
target[symbol] = target[symbol] ?? {};
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
target[symbol][prop] = val;
}

Expand All @@ -32,11 +32,11 @@ export function getObjectPropMeta(
prop?: string | symbol
) {
if (prop) {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
return target[symbol]?.[prop] ?? null;
}

// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
return target[symbol] ?? {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function updateDerivedProps(
const decoratorState = getDecoratorState(receiver.surface);
decoratorState.deriving = true;
keys(derivedProps).forEach(key => {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
receiver[key] = derivedProps[key];
});
decoratorState.deriving = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ export function startObserve(
) {
const proto = Object.getPrototypeOf(receiver);
const observeFn = getObserveMeta(proto, prop as string)!;
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
const observerDisposable = receiver[observerDisposableSymbol] ?? {};

// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
receiver[observerDisposableSymbol] = observerDisposable;

if (observerDisposable[prop]) {
Expand Down Expand Up @@ -114,7 +114,7 @@ export function initializeObservers(
});

receiver['_disposable'].add(() => {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
Object.values(receiver[observerDisposableSymbol] ?? {}).forEach(dispose =>
(dispose as () => void)()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export abstract class GfxPrimitiveElementModel<

const value = this._stashed.get(prop);
this._stashed.delete(prop);
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
delete this[prop];

if (getFieldPropsSet(this).has(prop as string)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ export abstract class GfxLocalElementModel implements GfxCompatibleInterface {
this._local.delete('deserializedXYWH');
}

// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
const oldValue = target[prop as string];

if (oldValue === value) {
return true;
}

// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
target[prop as string] = value;

if (!this._props.has(prop)) {
Expand All @@ -158,7 +158,7 @@ export abstract class GfxLocalElementModel implements GfxCompatibleInterface {
},
});

// eslint-disable-next-line no-constructor-return
// oxlint-disable-next-line no-constructor-return
return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {

Object.keys(rest).forEach(key => {
if (props[key] !== undefined) {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
elementModel.model[key] = props[key];
}
});
Expand Down Expand Up @@ -177,7 +177,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
state.skipField = options.skipFieldInit ?? false;

let mounted = false;
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
Ctor['_decoratorState'] = state;

const elementModel = new Ctor({
Expand All @@ -188,7 +188,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
onChange: payload => mounted && options.onChange({ id, ...payload }),
}) as GfxPrimitiveElementModel;

// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
delete Ctor['_decoratorState'];
state.creating = false;
state.skipField = false;
Expand Down Expand Up @@ -364,7 +364,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
{
const group = this.getGroup(payload.id);
if (group) {
// eslint-disable-next-line unicorn/prefer-dom-node-remove
// oxlint-disable-next-line unicorn/prefer-dom-node-remove
group.removeChild(payload.model as GfxModel);
}
}
Expand All @@ -385,7 +385,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
throw new Error(`Invalid element type: ${type}`);
}

// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
return (ctor.propsToY ?? GfxPrimitiveElementModel.propsToY)(props);
}

Expand Down Expand Up @@ -449,7 +449,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {

const id = nanoid();

// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
props.id = id;

const elementModel = this._createElementFromProps(props, {
Expand Down Expand Up @@ -502,7 +502,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
});
}

// eslint-disable-next-line unicorn/prefer-dom-node-remove
// oxlint-disable-next-line unicorn/prefer-dom-node-remove
group?.removeChild(element as GfxModel);

this.elements.getValue()!.delete(id);
Expand Down Expand Up @@ -612,7 +612,7 @@ export class SurfaceBlockModel extends BlockModel<SurfaceBlockProps> {
props as Record<string, unknown>
) as T;
Object.entries(props).forEach(([key, value]) => {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
elementModel[key] = value;
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export class ToolController extends GfxExtension {
});

get currentTool$() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
// oxlint-disable-next-line typescript/no-this-alias
const self = this;

return {
Expand All @@ -143,7 +143,7 @@ export class ToolController extends GfxExtension {
}

get currentToolOption$() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
// oxlint-disable-next-line typescript/no-this-alias
const self = this;

return {
Expand Down Expand Up @@ -475,7 +475,7 @@ export class ToolController extends GfxExtension {
};

this.std.provider.getAll(ToolIdentifier).forEach(tool => {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
tool['eventTarget'] = eventTarget;
this._register(tool);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export function toGfxBlockComponent<
WidgetName extends string,
B extends typeof BlockComponent<Model, Service, WidgetName>,
>(CustomBlock: B) {
// @ts-expect-error FIXME: ts error
// @ts-expect-error ignore
return class extends CustomBlock {
[GfxElementSymbol] = true;

Expand Down
Loading

0 comments on commit 2b27d62

Please sign in to comment.