style: add ban-ts-comment rule (#2738)

This commit is contained in:
LongYinan
2023-06-09 11:55:23 +08:00
committed by GitHub
parent c5a295a87b
commit 2e975e79dd
16 changed files with 139 additions and 91 deletions

View File

@@ -27,11 +27,11 @@ async function dispatch<
>(
namespace: T,
functionName: F,
// @ts-ignore
// @ts-expect-error
...args: Parameters<WithoutFirstParameter<MainIPCHandlerMap[T][F]>>
): // @ts-ignore
): // @ts-expect-error
ReturnType<MainIPCHandlerMap[T][F]> {
// @ts-ignore
// @ts-expect-error
const handlers = registeredHandlers.get(namespace + ':' + functionName);
assert(handlers);
@@ -108,7 +108,7 @@ const electronModule = {
registeredHandlers.set(name, handlers);
},
addListener: (...args: any[]) => {
// @ts-ignore
// @ts-expect-error
electronModule.app.on(...args);
},
removeListener: () => {},

View File

@@ -132,9 +132,9 @@ export function createApplicationMenu() {
},
];
// @ts-ignore The snippet is copied from Electron official docs.
// It's working as expected. No idea why it contains type errors.
// Just ignore for now.
// @ts-expect-error: The snippet is copied from Electron official docs.
// It's working as expected. No idea why it contains type errors.
// Just ignore for now.
const menu = Menu.buildFromTemplate(template);
Menu.setApplicationMenu(menu);

View File

@@ -32,7 +32,7 @@ const electronModule = {
registeredHandlers.set(name, handlers);
},
addListener: (...args: any[]) => {
// @ts-ignore
// @ts-expect-error
electronModule.app.on(...args);
},
removeListener: () => {},

View File

@@ -21,9 +21,9 @@ const page = blockSuiteWorkspace.createPage({ id: 'page0' });
const Editor: React.FC = () => {
const onLoad = useCallback((page: Page, editor: EditorContainer) => {
// @ts-ignore
// @ts-expect-error
globalThis.page = page;
// @ts-ignore
// @ts-expect-error
globalThis.editor = editor;
return () => void 0;
}, []);

View File

@@ -147,7 +147,7 @@ const SetDBLocationContent = ({
if (result?.filePath) {
onConfirmLocation(result.filePath);
} else if (result?.error) {
// @ts-expect-error
// @ts-expect-error: result.error is dynamic so the type is unknown
toast(t[result.error]());
}
};
@@ -278,7 +278,7 @@ export const CreateWorkspaceModal = ({
setStep('set-syncing-mode');
} else if (result.error || result.canceled) {
if (result.error) {
// @ts-expect-error
// @ts-expect-error: result.error is dynamic so the type is unknown
toast(t[result.error]());
}
onClose();
@@ -294,71 +294,92 @@ export const CreateWorkspaceModal = ({
};
}, [mode, onClose, t]);
const onConfirmEnableCloudSyncing = useCallback(
(enableCloudSyncing: boolean) => {
(async function () {
if (!config.enableLegacyCloud && enableCloudSyncing) {
setOpenDisableCloudAlertModal(true);
} else {
let id = addedId;
// syncing mode is also the last step
if (addedId && mode === 'add') {
await addLocalWorkspace(addedId);
} else if (mode === 'new' && workspaceName) {
id = await createLocalWorkspace(workspaceName);
// if dbFileLocation is set, move db file to that location
if (dbFileLocation) {
await window.apis?.dialog.moveDBFile(id, dbFileLocation);
}
} else {
logger.error('invalid state');
return;
}
if (id) {
onCreate(id);
}
}
})().catch(e => {
logger.error(e);
});
},
[
addLocalWorkspace,
addedId,
createLocalWorkspace,
dbFileLocation,
mode,
onCreate,
setOpenDisableCloudAlertModal,
workspaceName,
]
);
const nameWorkspaceNode =
step === 'name-workspace' ? (
<NameWorkspaceContent
// go to previous step instead?
onClose={onClose}
onConfirmName={async name => {
setWorkspaceName(name);
if (environment.isDesktop) {
setStep('set-syncing-mode');
} else {
// this will be the last step for web for now
// fix me later
const id = await createLocalWorkspace(name);
onCreate(id);
}
}}
/>
) : null;
const setDBLocationNode =
step === 'set-db-location' ? (
<SetDBLocationContent
onConfirmLocation={dir => {
setDBFileLocation(dir);
setStep('name-workspace');
}}
/>
) : null;
const setSyncingModeNode =
step === 'set-syncing-mode' ? (
<SetSyncingModeContent
mode={mode}
onConfirmMode={onConfirmEnableCloudSyncing}
/>
) : null;
return (
<Modal open={mode !== false && !!step} onClose={onClose}>
<ModalWrapper width={560} style={{ padding: '10px' }}>
<div className={style.header}>
<ModalCloseButton
top={6}
right={6}
onClick={() => {
onClose();
}}
/>
<ModalCloseButton top={6} right={6} onClick={onClose} />
</div>
{step === 'name-workspace' && (
<NameWorkspaceContent
// go to previous step instead?
onClose={onClose}
onConfirmName={async name => {
setWorkspaceName(name);
if (environment.isDesktop) {
setStep('set-syncing-mode');
} else {
// this will be the last step for web for now
// fix me later
const id = await createLocalWorkspace(name);
onCreate(id);
}
}}
/>
)}
{step === 'set-db-location' && (
<SetDBLocationContent
onConfirmLocation={dir => {
setDBFileLocation(dir);
setStep('name-workspace');
}}
/>
)}
{step === 'set-syncing-mode' && (
<SetSyncingModeContent
mode={mode}
onConfirmMode={async enableCloudSyncing => {
if (!config.enableLegacyCloud && enableCloudSyncing) {
setOpenDisableCloudAlertModal(true);
} else {
let id = addedId;
// syncing mode is also the last step
if (addedId && mode === 'add') {
await addLocalWorkspace(addedId);
} else if (mode === 'new' && workspaceName) {
id = await createLocalWorkspace(workspaceName);
// if dbFileLocation is set, move db file to that location
if (dbFileLocation) {
await window.apis?.dialog.moveDBFile(id, dbFileLocation);
}
} else {
logger.error('invalid state');
return;
}
if (id) {
onCreate(id);
}
}
}}
/>
)}
{nameWorkspaceNode}
{setDBLocationNode}
{setSyncingModeNode}
</ModalWrapper>
</Modal>
);

View File

@@ -109,8 +109,7 @@ const AffineRemoteCollaborationPanel: React.FC<
onClick={async () => {
// FIXME: remove ignore
// @ts-ignore
await removeMember(member.id);
await removeMember(Number(member.id));
toast(
t['Member has been removed']({
name: user.name,

View File

@@ -18,7 +18,7 @@ export const ExportPanel = () => {
if (id) {
const result = await window.apis?.dialog.saveDBFileAs(id);
if (result?.error) {
// @ts-expect-error
// @ts-expect-error: result.error is dynamic
toast(t[result.error]());
} else if (!result?.canceled) {
toast(t['Export success']());

View File

@@ -30,8 +30,7 @@ const useShowOpenDBFile = (workspaceId: string) => {
window.apis.workspace.getMeta(workspaceId).then(meta => {
setShow(!!meta.secondaryDBPath);
});
// @ts-expect-error
return window.events.workspace.onMetaChange(newMeta => {
return window.events.workspace.onMetaChange((newMeta: any) => {
if (newMeta.workspaceId === workspaceId) {
const meta = newMeta.meta;
setShow(!!meta.secondaryDBPath);
@@ -74,7 +73,7 @@ export const GeneralPanel: React.FC<PanelProps> = ({
if (!result?.error && !result?.canceled) {
toast(t['Move folder success']());
} else if (result?.error) {
// @ts-expect-error
// @ts-expect-error: result.error is dynamic
toast(t[result.error]());
}
} catch (err) {

View File

@@ -1,5 +1,5 @@
import { css, displayFlex, keyframes, styled } from '@affine/component';
// @ts-ignore
// @ts-expect-error: no types for css-spring
import spring, { toString } from 'css-spring';
const ANIMATE_DURATION = 400;