mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
refactor(editor): cleanup ts-expect-error (#9369)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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] ?? {};
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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]) {
|
||||
@@ -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)()
|
||||
);
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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)) {
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
});
|
||||
@@ -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({
|
||||
@@ -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;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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, {
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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 {
|
||||
@@ -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 {
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ describe('isEqual', () => {
|
||||
)
|
||||
).toBe(true);
|
||||
expect(isEqual({}, { foo: 1 })).toBe(false);
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(isEqual({ foo: 1 }, {})).toBe(false);
|
||||
});
|
||||
|
||||
@@ -63,7 +63,7 @@ describe('isEqual', () => {
|
||||
bigint: 110101195306153019n,
|
||||
};
|
||||
expect(isEqual(nested, nested)).toBe(true);
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(isEqual({ foo: [] }, { foo: '' })).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -114,9 +114,9 @@ export const debounce = <T extends (...args: any[]) => void>(
|
||||
};
|
||||
|
||||
export async function nextTick() {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error check window.scheduler
|
||||
if ('scheduler' in window && 'yield' in window.scheduler) {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error check window.scheduler.yield
|
||||
return window.scheduler.yield();
|
||||
} else if (typeof requestIdleCallback !== 'undefined') {
|
||||
return new Promise(resolve => requestIdleCallback(resolve));
|
||||
|
||||
@@ -162,7 +162,7 @@ export async function assertSelection(
|
||||
([richTextIndex]) => {
|
||||
const richText =
|
||||
document?.querySelectorAll('test-rich-text')[richTextIndex];
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error getInlineRange
|
||||
const inlineEditor = richText.inlineEditor;
|
||||
return inlineEditor?.getInlineRange();
|
||||
},
|
||||
|
||||
@@ -36,7 +36,7 @@ const spaceMetaId = 'meta';
|
||||
function serializCollection(doc: BlockSuiteDoc): Record<string, any> {
|
||||
const spaces = {};
|
||||
doc.spaces.forEach((subDoc, key) => {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
spaces[key] = subDoc.toJSON();
|
||||
});
|
||||
const json = doc.toJSON();
|
||||
@@ -103,7 +103,7 @@ describe('basic', () => {
|
||||
|
||||
assert.equal(collection.isEmpty, false);
|
||||
assert.equal(typeof actualDoc.createDate, 'number');
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
delete actualDoc.createDate;
|
||||
|
||||
assert.deepEqual(actual, {
|
||||
|
||||
@@ -177,7 +177,7 @@ test('always get latest value in onChange', () => {
|
||||
|
||||
let value: unknown;
|
||||
rootModel.propsUpdated.on(({ key }) => {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
value = rootModel[key];
|
||||
});
|
||||
|
||||
|
||||
@@ -96,23 +96,23 @@ test('snapshot to model', async () => {
|
||||
});
|
||||
expect(model.flavour).toBe(rootModel.flavour);
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(model.props.title).toBeInstanceOf(Text);
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
map.set('title', model.props.title.yText);
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(model.props.title.toString()).toBe('doc title');
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(model.props.style).toEqual({
|
||||
color: 'red',
|
||||
});
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(model.props.count).toBe(3);
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(model.props.items).toMatchObject([
|
||||
{
|
||||
id: 0,
|
||||
@@ -125,7 +125,7 @@ test('snapshot to model', async () => {
|
||||
},
|
||||
]);
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
model.props.items.forEach((item, index) => {
|
||||
expect(item.content).toBeInstanceOf(Text);
|
||||
const key = `item:${index}:content`;
|
||||
|
||||
@@ -49,11 +49,11 @@ describe('blocksuite yjs', () => {
|
||||
|
||||
proxy.obj2 = { foo: 2, bar: { num: 3 } };
|
||||
expect(map.get('obj2')).toBeInstanceOf(Y.Map);
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(map.get('obj2').get('bar').get('num')).toBe(3);
|
||||
|
||||
proxy.obj2.bar.str = 'hello';
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(map.get('obj2').get('bar').get('str')).toBe('hello');
|
||||
|
||||
proxy.obj3 = {};
|
||||
@@ -105,7 +105,7 @@ describe('blocksuite yjs', () => {
|
||||
|
||||
proxy.inner.native.setValue(['hello', 'world', 'foo']);
|
||||
expect(native.getValue()).toEqual(['hello', 'world', 'foo']);
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(map.get('inner').get('native').get('value')).toEqual([
|
||||
'hello',
|
||||
'world',
|
||||
@@ -114,10 +114,10 @@ describe('blocksuite yjs', () => {
|
||||
|
||||
const native2 = new Boxed(0);
|
||||
proxy.inner.native2 = native2;
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(map.get('inner').get('native2').get('value')).toBe(0);
|
||||
native2.setValue(1);
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error ignore
|
||||
expect(map.get('inner').get('native2').get('value')).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -150,7 +150,7 @@ function MagicProps(): {
|
||||
|
||||
const modelLabel = Symbol('model_label');
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
export class BlockModel<
|
||||
Props extends object = object,
|
||||
PropsSignal extends object = SignaledProps<Props>,
|
||||
|
||||
@@ -46,12 +46,12 @@ export class SyncController {
|
||||
const keyName = key.replace('prop:', '');
|
||||
const proxy = this._getPropsProxy(keyName, value);
|
||||
this._byPassUpdate(() => {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
this.model[keyName] = proxy;
|
||||
const signalKey = `${keyName}$`;
|
||||
this._mutex(() => {
|
||||
if (signalKey in this.model) {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
this.model[signalKey].value = y2Native(value);
|
||||
}
|
||||
});
|
||||
@@ -62,10 +62,10 @@ export class SyncController {
|
||||
if (type.action === 'delete') {
|
||||
const keyName = key.replace('prop:', '');
|
||||
this._byPassUpdate(() => {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
delete this.model[keyName];
|
||||
if (`${keyName}$` in this.model) {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
this.model[`${keyName}$`].value = undefined;
|
||||
}
|
||||
});
|
||||
@@ -136,7 +136,7 @@ export class SyncController {
|
||||
const value = data.value;
|
||||
if (!this.model) return;
|
||||
_mutex(() => {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
this.model[key] = value;
|
||||
});
|
||||
});
|
||||
@@ -208,7 +208,7 @@ export class SyncController {
|
||||
|
||||
function setValue(target: BlockModel, p: string, value: unknown) {
|
||||
_mutex(() => {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
target[`${p}$`].value = value;
|
||||
});
|
||||
}
|
||||
@@ -222,7 +222,7 @@ export class SyncController {
|
||||
const signalKey = `${name}$`;
|
||||
if (signalKey in this.model) {
|
||||
this._mutex(() => {
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow magic props
|
||||
this.model[signalKey].value = this.model[name];
|
||||
});
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export function syncBlockProps(
|
||||
if (SYS_KEYS.has(key)) return;
|
||||
if (value === undefined) return;
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow props
|
||||
model[key] = value;
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ export function syncBlockProps(
|
||||
return;
|
||||
}
|
||||
|
||||
// @ts-expect-error FIXME: ts error
|
||||
// @ts-expect-error allow props
|
||||
model[key] = native2Y(value);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user