build: enhance tsconfig type check (#2732)

This commit is contained in:
Himself65
2023-06-09 01:42:58 +08:00
committed by GitHub
parent fc9a9f479b
commit b383ce36cd
34 changed files with 111 additions and 68 deletions
@@ -29,13 +29,14 @@ export const quitAndInstall = async () => {
let lastCheckTime = 0; let lastCheckTime = 0;
export const checkForUpdatesAndNotify = async (force = true) => { export const checkForUpdatesAndNotify = async (force = true) => {
if (!_autoUpdater) { if (!_autoUpdater) {
return; // ? return void 0;
} }
// check every 30 minutes (1800 seconds) at most // check every 30 minutes (1800 seconds) at most
if (force || lastCheckTime + 1000 * 1800 < Date.now()) { if (force || lastCheckTime + 1000 * 1800 < Date.now()) {
lastCheckTime = Date.now(); lastCheckTime = Date.now();
return await _autoUpdater.checkForUpdatesAndNotify(); return await _autoUpdater.checkForUpdatesAndNotify();
} }
return void 0;
}; };
export const registerUpdater = async () => { export const registerUpdater = async () => {
@@ -27,6 +27,7 @@ import { contextBridge, ipcRenderer } from 'electron';
if (validateIPC(channel)) { if (validateIPC(channel)) {
return ipcRenderer.invoke(channel, ...args); return ipcRenderer.invoke(channel, ...args);
} }
return void 0;
}, },
on( on(
@@ -35,9 +36,8 @@ import { contextBridge, ipcRenderer } from 'electron';
) { ) {
if (validateIPC(channel)) { if (validateIPC(channel)) {
ipcRenderer.on(channel, listener); ipcRenderer.on(channel, listener);
return this;
} }
return this;
}, },
once( once(
@@ -46,9 +46,8 @@ import { contextBridge, ipcRenderer } from 'electron';
) { ) {
if (validateIPC(channel)) { if (validateIPC(channel)) {
ipcRenderer.once(channel, listener); ipcRenderer.once(channel, listener);
return this;
} }
return this;
}, },
removeListener( removeListener(
@@ -57,9 +56,8 @@ import { contextBridge, ipcRenderer } from 'electron';
) { ) {
if (validateIPC(channel)) { if (validateIPC(channel)) {
ipcRenderer.removeListener(channel, listener); ipcRenderer.removeListener(channel, listener);
return this;
} }
return this;
}, },
}, },
}; };
+2 -7
View File
@@ -1,10 +1,5 @@
import { import type { CanActivate, ExecutionContext } from '@nestjs/common';
CanActivate, import { createParamDecorator, Injectable, UseGuards } from '@nestjs/common';
createParamDecorator,
ExecutionContext,
Injectable,
UseGuards,
} from '@nestjs/common';
import { PrismaService } from '../../prisma'; import { PrismaService } from '../../prisma';
import { getRequestResponseFromContext } from '../../utils/nestjs'; import { getRequestResponseFromContext } from '../../utils/nestjs';
+1 -1
View File
@@ -9,7 +9,7 @@ import {
ResolveField, ResolveField,
Resolver, Resolver,
} from '@nestjs/graphql'; } from '@nestjs/graphql';
import { Request } from 'express'; import type { Request } from 'express';
import { UserType } from '../users/resolver'; import { UserType } from '../users/resolver';
import { CurrentUser } from './guard'; import { CurrentUser } from './guard';
+1 -1
View File
@@ -4,7 +4,7 @@ import {
UnauthorizedException, UnauthorizedException,
} from '@nestjs/common'; } from '@nestjs/common';
import { compare, hash } from '@node-rs/bcrypt'; import { compare, hash } from '@node-rs/bcrypt';
import { User } from '@prisma/client'; import type { User } from '@prisma/client';
import jwt from 'jsonwebtoken'; import jwt from 'jsonwebtoken';
import { Config } from '../../config'; import { Config } from '../../config';
+1 -1
View File
@@ -1,7 +1,7 @@
import { equal, ok } from 'node:assert'; import { equal, ok } from 'node:assert';
import { afterEach, beforeEach, describe, test } from 'node:test'; import { afterEach, beforeEach, describe, test } from 'node:test';
import { INestApplication } from '@nestjs/common'; import type { INestApplication } from '@nestjs/common';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
import { hash } from '@node-rs/bcrypt'; import { hash } from '@node-rs/bcrypt';
import { PrismaClient } from '@prisma/client'; import { PrismaClient } from '@prisma/client';
+4 -7
View File
@@ -1,10 +1,7 @@
import { ArgumentsHost, ExecutionContext } from '@nestjs/common'; import type { ArgumentsHost, ExecutionContext } from '@nestjs/common';
import { import type { GqlContextType } from '@nestjs/graphql';
GqlArgumentsHost, import { GqlArgumentsHost, GqlExecutionContext } from '@nestjs/graphql';
GqlContextType, import type { Request, Response } from 'express';
GqlExecutionContext,
} from '@nestjs/graphql';
import { Request, Response } from 'express';
export function getRequestResponseFromContext(context: ExecutionContext) { export function getRequestResponseFromContext(context: ExecutionContext) {
switch (context.getType<GqlContextType>()) { switch (context.getType<GqlContextType>()) {
@@ -30,7 +30,7 @@ export class AffineErrorBoundary extends Component<
AffineErrorBoundaryProps, AffineErrorBoundaryProps,
AffineErrorBoundaryState AffineErrorBoundaryState
> { > {
public state: AffineErrorBoundaryState = { public override state: AffineErrorBoundaryState = {
error: null, error: null,
}; };
@@ -40,11 +40,11 @@ export class AffineErrorBoundary extends Component<
return { error }; return { error };
} }
public componentDidCatch(error: AffineError, errorInfo: ErrorInfo) { public override componentDidCatch(error: AffineError, errorInfo: ErrorInfo) {
console.error('Uncaught error:', error, errorInfo); console.error('Uncaught error:', error, errorInfo);
} }
public render(): ReactNode { public override render(): ReactNode {
if (this.state.error) { if (this.state.error) {
const error = this.state.error; const error = this.state.error;
if (error instanceof PageNotFoundError) { if (error instanceof PageNotFoundError) {
@@ -80,6 +80,7 @@ const PageListEmpty = (props: {
if (listType === 'shared') { if (listType === 'shared') {
return t['emptySharedPages'](); return t['emptySharedPages']();
} }
return;
}; };
return ( return (
@@ -268,6 +268,7 @@ export const WorkspaceLayout: FC<PropsWithChildren> =
affineGlobalChannel.disconnect(); affineGlobalChannel.disconnect();
}; };
} }
return;
}, [currentWorkspaceId, jotaiWorkspaces]); }, [currentWorkspaceId, jotaiWorkspaces]);
const Provider = const Provider =
+2 -2
View File
@@ -12,7 +12,7 @@ const description =
export default class AppDocument extends Document<{ export default class AppDocument extends Document<{
emotionStyleTags: EmotionJSX.Element[]; emotionStyleTags: EmotionJSX.Element[];
}> { }> {
static getInitialProps = async (ctx: DocumentContext) => { static override getInitialProps = async (ctx: DocumentContext) => {
const originalRenderPage = ctx.renderPage; const originalRenderPage = ctx.renderPage;
const cache = createEmotionCache(); const cache = createEmotionCache();
@@ -41,7 +41,7 @@ export default class AppDocument extends Document<{
emotionStyleTags, emotionStyleTags,
}; };
}; };
render() { override render() {
return ( return (
<Html> <Html>
<Head> <Head>
+1
View File
@@ -63,6 +63,7 @@ const IndexPageInner = () => {
} else { } else {
console.warn('No target workspace. This should not happen in production'); console.warn('No target workspace. This should not happen in production');
} }
return;
}, [helper, jumpToPage, jumpToSubPath, router, workspaces]); }, [helper, jumpToPage, jumpToSubPath, router, workspaces]);
return ( return (
@@ -30,6 +30,7 @@ function useMouseOffset() {
el.removeEventListener('mouseleave', onMouseLeave); el.removeEventListener('mouseleave', onMouseLeave);
}; };
} }
return () => {};
}, []); }, []);
return [offset, outside, ref] as const; return [offset, outside, ref] as const;
@@ -80,6 +80,7 @@ const BlockSuiteEditorImpl = (props: EditorProps): ReactElement => {
.forEach(dispose => dispose()); .forEach(dispose => dispose());
}; };
} }
return () => {};
}, [editor, editor.page, page, onLoad]); }, [editor, editor.page, page, onLoad]);
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
@@ -13,4 +13,5 @@ previewBlockIdAtom.onMount = set => {
window.removeEventListener('affine.embed-block-db-click', callback); window.removeEventListener('affine.embed-block-db-click', callback);
}; };
} }
return () => {};
}; };
@@ -183,6 +183,7 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
if (notification.undo) { if (notification.undo) {
return notification.undo(); return notification.undo();
} }
return void 0;
}, [notification]); }, [notification]);
useEffect(() => { useEffect(() => {
@@ -200,6 +201,7 @@ function NotificationCard(props: NotificationCardProps): ReactElement {
h.filter(height => height.notificationKey !== notification.key) h.filter(height => height.notificationKey !== notification.key)
); );
} }
return () => {};
}, [notification.key, setHeights]); }, [notification.key, setHeights]);
return ( return (
<Toast.Root <Toast.Root
@@ -1,4 +1,7 @@
export * from './all-page'; export * from './all-page';
export * from './components/favorite-tag';
export * from './components/new-page-buttton';
export * from './components/title-cell';
export * from './filter'; export * from './filter';
export * from './operation-cell'; export * from './operation-cell';
export * from './operation-menu-items'; export * from './operation-menu-items';
@@ -1,2 +1,4 @@
export * from './disable-public-link'; export * from './disable-public-link';
export * from './share-menu'; export * from './share-menu';
export * from './share-workspace';
export * from './styles';
@@ -33,4 +33,5 @@ export function findNode<RenderProps>(
} }
} }
} }
return undefined;
} }
+1
View File
@@ -12,6 +12,7 @@
}, },
"exports": { "exports": {
".": "./src/index.ts", ".": "./src/index.ts",
"./api": "./src/api.ts",
"./config": "./src/config.ts", "./config": "./src/config.ts",
"./constant": "./src/constant.ts", "./constant": "./src/constant.ts",
"./workspace": "./src/workspace.ts", "./workspace": "./src/workspace.ts",
@@ -43,6 +43,7 @@ export function useBlockSuiteWorkspaceAvatarUrl(
dispose.dispose(); dispose.dispose();
}; };
} }
return () => {};
}, [blockSuiteWorkspace]); }, [blockSuiteWorkspace]);
return [avatar ?? null, setAvatar] as const; return [avatar ?? null, setAvatar] as const;
} }
+1
View File
@@ -102,6 +102,7 @@ export function setUpLanguage(i: i18n) {
} }
return i.changeLanguage(language); return i.changeLanguage(language);
} }
return void 0;
} }
// const I18nProvider = I18nextProvider; // const I18nProvider = I18nextProvider;
+2 -2
View File
@@ -1,6 +1,6 @@
// cSpell:ignore Tolgee // cSpell:ignore Tolgee
import fs from 'node:fs/promises'; import * as fs from 'node:fs/promises';
import path from 'node:path'; import * as path from 'node:path';
import { format } from 'prettier'; import { format } from 'prettier';
+3 -7
View File
@@ -1,16 +1,12 @@
// cSpell:ignore Tolgee // cSpell:ignore Tolgee
import { resolve } from 'node:path';
import { readFile } from 'fs/promises'; import { readFile } from 'fs/promises';
import path from 'path';
import { createsNewKey, getRemoteTranslations } from './api.js'; import { createsNewKey, getRemoteTranslations } from './api.js';
import type { TranslationRes } from './utils.js'; import type { TranslationRes } from './utils.js';
const BASE_JSON_PATH = path.resolve( const BASE_JSON_PATH = resolve(process.cwd(), 'src', 'resources', 'en.json');
process.cwd(),
'src',
'resources',
'en.json'
);
const BASE_LANGUAGES = 'en' as const; const BASE_LANGUAGES = 'en' as const;
/** /**
@@ -1,11 +1,11 @@
import { Empty } from '@affine/component'; import { Empty } from '@affine/component';
import { toast } from '@affine/component'; import { toast } from '@affine/component';
import { AffineLoading } from '@affine/component/affine-loading'; import { AffineLoading } from '@affine/component/affine-loading';
import { PageListTrashView } from '@affine/component/page-list/all-page'; import type { OperationCellProps } from '@affine/component/page-list';
import { PageList } from '@affine/component/page-list/all-page'; import { PageListTrashView } from '@affine/component/page-list';
import { NewPageButton } from '@affine/component/page-list/components/new-page-buttton'; import { PageList } from '@affine/component/page-list';
import type { OperationCellProps } from '@affine/component/page-list/operation-cell'; import { NewPageButton } from '@affine/component/page-list';
import { OperationCell } from '@affine/component/page-list/operation-cell'; import { OperationCell } from '@affine/component/page-list';
import { PageIcon } from '@blocksuite/icons'; import { PageIcon } from '@blocksuite/icons';
import { expect } from '@storybook/jest'; import { expect } from '@storybook/jest';
import type { StoryFn } from '@storybook/react'; import type { StoryFn } from '@storybook/react';
@@ -1,7 +1,9 @@
import { toast } from '@affine/component'; import { toast } from '@affine/component';
import { PublicLinkDisableModal } from '@affine/component/share-menu/disable-public-link'; import {
PublicLinkDisableModal,
StyledDisableButton,
} from '@affine/component/share-menu';
import { ShareMenu } from '@affine/component/share-menu/share-menu'; import { ShareMenu } from '@affine/component/share-menu/share-menu';
import { StyledDisableButton } from '@affine/component/share-menu/styles';
import type { import type {
AffineLegacyCloudWorkspace, AffineLegacyCloudWorkspace,
LocalWorkspace, LocalWorkspace,
+5 -1
View File
@@ -4,7 +4,11 @@
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"noEmit": false, "noEmit": false,
"outDir": "lib" "outDir": "lib",
"paths": {
"@affine/component": ["../component/src"],
"@affine/component/*": ["../component/src/components/*"]
}
}, },
"references": [ "references": [
{ {
+1 -1
View File
@@ -1,5 +1,5 @@
{ {
"extends": "./tsconfig.json", "extends": "../../tsconfig.json",
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"module": "ESNext", "module": "ESNext",
+1
View File
@@ -75,6 +75,7 @@ const signInWithElectron = async (firebaseAuth: FirebaseAuth) => {
const user = await signInWithCredential(firebaseAuth, credential); const user = await signInWithCredential(firebaseAuth, credential);
return await user.user.getIdToken(); return await user.user.getIdToken();
} }
return void 0;
}; };
export const clearLoginStorage = () => { export const clearLoginStorage = () => {
+2
View File
@@ -48,6 +48,7 @@ rootCurrentWorkspaceIdAtom.onMount = set => {
Router.events.off('routeChangeStart', callback); Router.events.off('routeChangeStart', callback);
}; };
} }
return () => {};
}; };
export const rootCurrentPageIdAtom = atom<string | null>(null); export const rootCurrentPageIdAtom = atom<string | null>(null);
@@ -68,6 +69,7 @@ rootCurrentPageIdAtom.onMount = set => {
Router.events.off('routeChangeStart', callback); Router.events.off('routeChangeStart', callback);
}; };
} }
return () => {};
}; };
// current editor atom, each app should have only one editor in the same time // current editor atom, each app should have only one editor in the same time
+2 -2
View File
@@ -101,7 +101,7 @@ export class CallbackSet extends Set<() => void> {
this.#ready = v; this.#ready = v;
} }
add(cb: () => void) { override add(cb: () => void) {
if (this.ready) { if (this.ready) {
cb(); cb();
return this; return this;
@@ -112,7 +112,7 @@ export class CallbackSet extends Set<() => void> {
return super.add(cb); return super.add(cb);
} }
delete(cb: () => void) { override delete(cb: () => void) {
if (this.has(cb)) { if (this.has(cb)) {
return super.delete(cb); return super.delete(cb);
} }
+1
View File
@@ -117,6 +117,7 @@ export async function tryMigrate(
} }
); );
} }
return void 0;
}) })
); );
localStorage.setItem(`${dbName}-migration`, 'true'); localStorage.setItem(`${dbName}-migration`, 'true');
@@ -80,7 +80,7 @@ export class IndexedDBVectorStore extends VectorStore {
return result; return result;
} }
static async fromTexts( static override async fromTexts(
texts: string[], texts: string[],
metadatas: object[] | object, metadatas: object[] | object,
embeddings: Embeddings, embeddings: Embeddings,
@@ -98,7 +98,7 @@ export class IndexedDBVectorStore extends VectorStore {
return IndexedDBVectorStore.fromDocuments(docs, embeddings, dbConfig); return IndexedDBVectorStore.fromDocuments(docs, embeddings, dbConfig);
} }
static async fromDocuments( static override async fromDocuments(
docs: Document[], docs: Document[],
embeddings: Embeddings, embeddings: Embeddings,
dbConfig?: MemoryVectorStoreArgs dbConfig?: MemoryVectorStoreArgs
+46 -17
View File
@@ -1,28 +1,57 @@
{ {
"compilerOptions": { "compilerOptions": {
"rootDir": ".", "verbatimModuleSyntax": true,
"target": "ESNext", // Classification follows https://www.typescriptlang.org/tsconfig
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true, // Type Checking
"skipLibCheck": true,
"strict": true, "strict": true,
"forceConsistentCasingInFileNames": true, // exactOptionalPropertyTypes: false,
// FIXME: add this back "noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": false, "noImplicitAny": true,
"esModuleInterop": true, "noImplicitOverride": true,
"module": "esnext", "noImplicitReturns": true,
"moduleResolution": "node", "noImplicitThis": true,
// noPropertyAccessFromIndexSignature: false,
// noUncheckedIndexedAccess: false,
// noUnusedLocals: false,
// noUnusedParameters: false,
"useUnknownInCatchVariables": true,
// Modules
"module": "ES2022",
"moduleResolution": "Node",
"resolveJsonModule": true, "resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
// Project // Emit
"incremental": true, "declaration": true,
"composite": true, "declarationMap": true,
"sourceMap": true,
// skip type emit for @internal types
// "stripInternal": true,
// JavaScript Support
"allowJs": false,
"checkJs": false,
// Interop Constraints
"forceConsistentCasingInFileNames": true,
"allowSyntheticDefaultImports": true,
// Language and Environment
"jsx": "react-jsx",
"lib": ["ES2023", "DOM", "DOM.Iterable"],
"target": "ES2022",
"useDefineForClassFields": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"baseUrl": ".",
// Projects
"composite": true,
"incremental": true,
// Completeness
"skipLibCheck": true, // skip all type checks for .d.ts files
"paths": { "paths": {
"@affine/component": ["./packages/component/src/index"], "@affine/component": ["./packages/component/src/index"],
"@affine/component/*": [ "@affine/component/*": [