chore: More typescript FIXME's removed

This commit is contained in:
Tom Moor
2022-01-06 21:25:42 -08:00
parent 8d05c752ea
commit c6cc04cad8
58 changed files with 199 additions and 221 deletions

View File

@@ -1,4 +1,3 @@
import { find } from "lodash";
import * as React from "react";
import { useMenuState, MenuButton } from "reakit/Menu";
import styled from "styled-components";
@@ -34,11 +33,8 @@ const FilterOptions = ({
modal: true,
});
const selected =
find(options, {
key: activeKey,
}) || options[0];
options.find((option) => option.key === activeKey) || options[0];
// @ts-expect-error ts-migrate(2339) FIXME: Property 'label' does not exist on type 'number | ... Remove this comment to see the full error message
const selectedLabel = selected ? `${selectedPrefix} ${selected.label}` : "";
return (

View File

@@ -41,7 +41,6 @@ class GroupListItem extends React.Component<Props> {
const membershipsInGroup = groupMemberships.inGroup(group.id);
const users = membershipsInGroup
.slice(0, MAX_AVATAR_DISPLAY)
// @ts-expect-error ts-migrate(2339) FIXME: Property 'user' does not exist on type 'GroupMembe... Remove this comment to see the full error message
.map((gm) => gm.user);
const overflow = memberCount - users.length;

View File

@@ -64,8 +64,7 @@ describe("PaginatedList", () => {
});
it("calls fetch when options prop changes", async () => {
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1-3 arguments, but got 0.
const fetchedItems = Array(DEFAULT_PAGINATION_LIMIT).fill();
const fetchedItems = Array(DEFAULT_PAGINATION_LIMIT).fill(undefined);
const fetch = jest.fn().mockReturnValue(Promise.resolve(fetchedItems));
const list = shallow(
<PaginatedList

View File

@@ -51,15 +51,10 @@ function Table({
headerGroups,
rows,
prepareRow,
// @ts-expect-error ts-migrate(2339) FIXME: Property 'canNextPage' does not exist on type 'Tab... Remove this comment to see the full error message
canNextPage,
// @ts-expect-error ts-migrate(2339) FIXME: Property 'nextPage' does not exist on type 'TableI... Remove this comment to see the full error message
nextPage,
// @ts-expect-error ts-migrate(2339) FIXME: Property 'canPreviousPage' does not exist on type ... Remove this comment to see the full error message
canPreviousPage,
// @ts-expect-error ts-migrate(2339) FIXME: Property 'previousPage' does not exist on type 'Ta... Remove this comment to see the full error message
previousPage,
// @ts-expect-error ts-migrate(2339) FIXME: Property 'pageIndex' does not exist on type 'Table... Remove this comment to see the full error message
state: { pageIndex, sortBy },
} = useTable(
{
@@ -71,7 +66,6 @@ function Table({
autoResetPage: false,
pageCount: totalPages,
initialState: {
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ sortBy: { id: string; desc: boolean; }[]; ... Remove this comment to see the full error message
sortBy: [
{
id: defaultSort,
@@ -82,7 +76,6 @@ function Table({
pageIndex: page,
},
stateReducer: (newState, action, prevState) => {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'sortBy' does not exist on type 'TableSta... Remove this comment to see the full error message
if (!isEqual(newState.sortBy, prevState.sortBy)) {
return { ...newState, pageIndex: 0 };
}
@@ -127,20 +120,15 @@ function Table({
{headerGroups.map((headerGroup) => (
<tr {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column) => (
// @ts-expect-error ts-migrate(2339) FIXME: Property 'getSortByToggleProps' does not exist on ... Remove this comment to see the full error message
<Head {...column.getHeaderProps(column.getSortByToggleProps())}>
<SortWrapper align="center" gap={4}>
{column.render("Header")}
{
// @ts-expect-error known issue: https://github.com/tannerlinsley/react-table/issues/2970
column.isSorted &&
// @ts-expect-error ts-migrate(2339) FIXME: Property 'isSortedDesc' does not exist on type 'He... Remove this comment to see the full error message
(column.isSortedDesc ? (
<DescSortIcon />
) : (
<AscSortIcon />
))
}
{column.isSorted &&
(column.isSortedDesc ? (
<DescSortIcon />
) : (
<AscSortIcon />
))}
</SortWrapper>
</Head>
))}

View File

@@ -1,4 +1,5 @@
import BaseModel from "./BaseModel";
import User from "./User";
class GroupMembership extends BaseModel {
id: string;
@@ -6,6 +7,8 @@ class GroupMembership extends BaseModel {
userId: string;
groupId: string;
user: User;
}
export default GroupMembership;

View File

@@ -12,8 +12,7 @@ import Time from "~/components/Time";
import useCurrentUser from "~/hooks/useCurrentUser";
import UserMenu from "~/menus/UserMenu";
// @ts-expect-error ts-migrate(2344) FIXME: Type 'Props' does not satisfy the constraint 'Comp... Remove this comment to see the full error message
const Table = React.lazy<TableProps>(
const Table = React.lazy(
() =>
import(
/* webpackChunkName: "table" */
@@ -40,38 +39,36 @@ function PeopleTable({ canManage, ...rest }: Props) {
id: "name",
Header: t("Name"),
accessor: "name",
// @ts-expect-error ts-migrate(7031) FIXME: Binding element 'value' implicitly has an 'any' ty... Remove this comment to see the full error message
Cell: observer(({ value, row }) => (
<Flex align="center" gap={8}>
<Avatar src={row.original.avatarUrl} size={32} /> {value}{" "}
{currentUser.id === row.original.id && `(${t("You")})`}
</Flex>
)),
Cell: observer(
({ value, row }: { value: string; row: { original: User } }) => (
<Flex align="center" gap={8}>
<Avatar src={row.original.avatarUrl} size={32} /> {value}{" "}
{currentUser.id === row.original.id && `(${t("You")})`}
</Flex>
)
),
},
canManage
? {
id: "email",
Header: t("Email"),
accessor: "email",
// @ts-expect-error ts-migrate(7031) FIXME: Binding element 'value' implicitly has an 'any' ty... Remove this comment to see the full error message
Cell: observer(({ value }) => value),
Cell: observer(({ value }: { value: string }) => <>{value}</>),
}
: undefined,
{
id: "lastActiveAt",
Header: t("Last active"),
accessor: "lastActiveAt",
Cell: observer(
// @ts-expect-error ts-migrate(7031) FIXME: Binding element 'value' implicitly has an 'any' ty... Remove this comment to see the full error message
({ value }) => value && <Time dateTime={value} addSuffix />
Cell: observer(({ value }: { value: string }) =>
value ? <Time dateTime={value} addSuffix /> : null
),
},
{
id: "isAdmin",
Header: t("Role"),
accessor: "rank",
// @ts-expect-error ts-migrate(7031) FIXME: Binding element 'row' implicitly has an 'any' type... Remove this comment to see the full error message
Cell: observer(({ row }) => (
Cell: observer(({ row }: { row: { original: User } }) => (
<Badges>
{!row.original.lastActiveAt && <Badge>{t("Invited")}</Badge>}
{row.original.isAdmin && <Badge primary>{t("Admin")}</Badge>}
@@ -86,16 +83,17 @@ function PeopleTable({ canManage, ...rest }: Props) {
accessor: "id",
className: "actions",
Cell: observer(
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '({ row, value }: { row: any; val... Remove this comment to see the full error message
({ row, value }) =>
currentUser.id !== value && <UserMenu user={row.original} />
({ row, value }: { value: string; row: { original: User } }) =>
currentUser.id !== value ? (
<UserMenu user={row.original} />
) : null
),
}
: undefined,
].filter((i) => i),
[t, canManage, currentUser]
);
// @ts-expect-error ts-migrate(2322) FIXME: Type '{ data: any[] & User[]; offset?: number | un... Remove this comment to see the full error message
return <Table columns={columns} {...rest} />;
}

View File

@@ -257,8 +257,7 @@ export default class DocumentsStore extends BaseStore<Document> {
this.backlinks.set(
documentId,
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'doc' implicitly has an 'any' type.
data.map((doc) => doc.id)
data.map((doc: Partial<Document>) => doc.id)
);
});
};
@@ -401,15 +400,13 @@ export default class DocumentsStore extends BaseStore<Document> {
invariant(res && res.data, "Search response should be available");
// add the documents and associated policies to the store
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'result' implicitly has an 'any' type.
res.data.forEach((result) => this.add(result.document));
res.data.forEach((result: SearchResult) => this.add(result.document));
this.addPolicies(res.policies);
// store a reference to the document model in the search cache instead
// of the original result from the API.
const results: SearchResult[] = compact(
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'result' implicitly has an 'any' type.
res.data.map((result) => {
res.data.map((result: SearchResult) => {
const document = this.data.get(result.document.id);
if (!document) return null;
return {

View File

@@ -79,8 +79,7 @@ class UiStore {
"(prefers-color-scheme: dark)"
);
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'event' implicitly has an 'any' type.
const setSystemTheme = (event) => {
const setSystemTheme = (event: MediaQueryListEvent | MediaQueryList) => {
this.systemTheme = event.matches ? SystemTheme.Dark : SystemTheme.Light;
};

View File

@@ -12,3 +12,5 @@ declare module "*.png" {
const value: any;
export = value;
}
declare const EDITOR_VERSION: string;

55
app/typings/react-table.d.ts vendored Normal file
View File

@@ -0,0 +1,55 @@
/* eslint-disable @typescript-eslint/ban-types */
import {
UsePaginationInstanceProps,
UsePaginationOptions,
UsePaginationState,
UseSortByColumnOptions,
UseSortByColumnProps,
UseSortByHooks,
UseSortByInstanceProps,
UseSortByOptions,
UseSortByState,
} from "react-table";
declare module "react-table" {
export interface TableOptions<D extends object>
extends UseExpandedOptions<D>,
UsePaginationOptions<D>,
UseSortByOptions<D>,
// note that having Record here allows you to add anything to the options, this matches the spirit of the
// underlying js library, but might be cleaner if it's replaced by a more specific type that matches your
// feature set, this is a safe default.
Record<string, any> {}
export interface Hooks<D extends object = {}>
extends UseExpandedHooks<D>,
UseSortByHooks<D> {}
export interface TableInstance<D extends object = {}>
extends UsePaginationInstanceProps<D>,
UseSortByInstanceProps<D> {}
export interface TableState<D extends object = {}>
extends UseColumnOrderState<D>,
UseExpandedState<D>,
UsePaginationState<D>,
UseSortByState<D> {}
export interface ColumnInterface<D extends object = {}>
extends UseResizeColumnsColumnOptions<D>,
UseSortByColumnOptions<D> {}
export interface ColumnInstance<D extends object = {}>
extends UseResizeColumnsColumnProps<D>,
UseSortByColumnProps<D> {}
export interface Cell<D extends object = {}>
extends UseGroupByCellProps<D>,
UseRowStateCellProps<D> {}
export interface Row<D extends object = {}>
extends UseExpandedRowProps<D>,
UseGroupByRowProps<D>,
UseRowSelectRowProps<D>,
UseRowStateRowProps<D> {}
}

View File

@@ -38,10 +38,10 @@ class ApiClient {
fetch = async (
path: string,
method: string,
data: (Record<string, any> | undefined) | FormData,
data: Record<string, any> | FormData | undefined,
options: Record<string, any> = {}
) => {
let body;
let body: string | FormData | undefined;
let modifiedPath;
let urlToFetch;
let isJson;
@@ -53,7 +53,9 @@ class ApiClient {
modifiedPath = path;
}
} else if (method === "POST" || method === "PUT") {
body = data || undefined;
if (data instanceof FormData || typeof data === "string") {
body = data;
}
// Only stringify data if its a normal object and
// not if it's [object FormData], in addition to
@@ -76,7 +78,6 @@ class ApiClient {
const headerOptions: any = {
Accept: "application/json",
"cache-control": "no-cache",
// @ts-expect-error ts-migrate(2304) FIXME: Cannot find name 'EDITOR_VERSION'.
"x-editor-version": EDITOR_VERSION,
pragma: "no-cache",
};
@@ -100,7 +101,6 @@ class ApiClient {
try {
response = await fetchWithRetry(urlToFetch, {
method,
// @ts-expect-error ts-migrate(2322) FIXME: Type 'string | Record<string, any> | undefined' is... Remove this comment to see the full error message
body,
headers,
redirect: "follow",
@@ -137,58 +137,52 @@ class ApiClient {
}
// Handle failed responses
const error = {};
// @ts-expect-error ts-migrate(2339) FIXME: Property 'statusCode' does not exist on type '{}'.
const error: {
statusCode?: number;
response?: Response;
message?: string;
error?: string;
data?: Record<string, any>;
} = {};
error.statusCode = response.status;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'response' does not exist on type '{}'.
error.response = response;
try {
const parsed = await response.json();
// @ts-expect-error ts-migrate(2339) FIXME: Property 'message' does not exist on type '{}'.
error.message = parsed.message || "";
// @ts-expect-error ts-migrate(2339) FIXME: Property 'error' does not exist on type '{}'.
error.error = parsed.error;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'data' does not exist on type '{}'.
error.data = parsed.data;
} catch (_err) {
// we're trying to parse an error so JSON may not be valid
}
// @ts-expect-error ts-migrate(2339) FIXME: Property 'error' does not exist on type '{}'.
if (response.status === 400 && error.error === "editor_update_required") {
window.location.reload();
// @ts-expect-error ts-migrate(2339) FIXME: Property 'message' does not exist on type '{}'.
throw new UpdateRequiredError(error.message);
}
if (response.status === 400) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'message' does not exist on type '{}'.
throw new BadRequestError(error.message);
}
if (response.status === 403) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'error' does not exist on type '{}'.
if (error.error === "user_suspended") {
stores.auth.logout();
return;
}
// @ts-expect-error ts-migrate(2339) FIXME: Property 'message' does not exist on type '{}'.
throw new AuthorizationError(error.message);
}
if (response.status === 404) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'message' does not exist on type '{}'.
throw new NotFoundError(error.message);
}
if (response.status === 503) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'message' does not exist on type '{}'.
throw new ServiceUnavailableError(error.message);
}
// @ts-expect-error ts-migrate(2339) FIXME: Property 'message' does not exist on type '{}'.
throw new RequestError(error.message);
};

View File

@@ -4,11 +4,9 @@ export default function getDataTransferFiles(
| React.FormEvent<HTMLInputElement>
| React.DragEvent<HTMLElement>
): File[] {
let dataTransferItemsList = [];
let dataTransferItemsList!: FileList | DataTransferItemList;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'dataTransfer' does not exist on type 'Sy... Remove this comment to see the full error message
if (event.dataTransfer) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'dataTransfer' does not exist on type 'Sy... Remove this comment to see the full error message
if ("dataTransfer" in event) {
const dt = event.dataTransfer;
if (dt.files && dt.files.length) {
@@ -18,12 +16,13 @@ export default function getDataTransferFiles(
// but Chrome implements some drag store, which is accesible via dataTransfer.items
dataTransferItemsList = dt.items;
}
// @ts-expect-error ts-migrate(2339) FIXME: Property 'files' does not exist on type 'EventTarg... Remove this comment to see the full error message
} else if (event.target && event.target.files) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'files' does not exist on type 'EventTarg... Remove this comment to see the full error message
} else if (event.target && "files" in event.target) {
// @ts-expect-error fallback
dataTransferItemsList = event.target.files;
}
// Convert from DataTransferItemsList to the native Array
return Array.prototype.slice.call(dataTransferItemsList);
return dataTransferItemsList
? Array.prototype.slice.call(dataTransferItemsList)
: [];
}

View File

@@ -230,7 +230,7 @@
"@types/react-medium-image-zoom": "^3.0.1",
"@types/react-portal": "^4.0.4",
"@types/react-router-dom": "^5.3.2",
"@types/react-table": "^7.7.8",
"@types/react-table": "^7.7.9",
"@types/react-virtualized-auto-sizer": "^1.0.1",
"@types/react-window": "^1.8.5",
"@types/semver": "^7.3.9",

View File

@@ -45,18 +45,9 @@ export default async function collectionImporter({
}
// store progress and pointers
// @ts-expect-error ts-migrate(2741) FIXME: Property 'string' is missing in type '{}' but requ... Remove this comment to see the full error message
const collections: {
string: Collection;
} = {};
// @ts-expect-error ts-migrate(2741) FIXME: Property 'string' is missing in type '{}' but requ... Remove this comment to see the full error message
const documents: {
string: Document;
} = {};
// @ts-expect-error ts-migrate(2741) FIXME: Property 'string' is missing in type '{}' but requ... Remove this comment to see the full error message
const attachments: {
string: Attachment;
} = {};
const collections: Record<string, Collection> = {};
const documents: Record<string, Document> = {};
const attachments: Record<string, Attachment> = {};
for (const item of items) {
if (item.type === "collection") {
@@ -113,6 +104,7 @@ export default async function collectionImporter({
const tmpDir = os.tmpdir();
const tmpFilePath = `${tmpDir}/upload-${uuidv4()}`;
await fs.promises.writeFile(tmpFilePath, content);
const file = new File({
name,
type: "text/markdown",
@@ -123,6 +115,7 @@ export default async function collectionImporter({
user,
ip,
});
await fs.promises.unlink(tmpFilePath);
// must be a nested document, find and reference the parent document
let parentDocumentId;
@@ -142,10 +135,8 @@ export default async function collectionImporter({
collectionId: collection.id,
createdAt: item.metadata.createdAt
? new Date(item.metadata.createdAt)
: // @ts-expect-error ts-migrate(2339) FIXME: Property 'date' does not exist on type 'Item'.
item.date,
// @ts-expect-error ts-migrate(2339) FIXME: Property 'date' does not exist on type 'Item'.
updatedAt: item.date,
: item.item.date,
updatedAt: item.item.date,
parentDocumentId,
user,
ip,

View File

@@ -1,7 +1,5 @@
import fs from "fs";
import path from "path";
import File from "formidable/lib/file";
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'jopl... Remove this comment to see the full error message
import { strikethrough, tables } from "joplin-turndown-plugin-gfm";
import mammoth from "mammoth";
import quotedPrintable from "quoted-printable";
@@ -21,6 +19,7 @@ const turndownService = new TurndownService({
bulletListMarker: "-",
headingStyle: "atx",
});
// Use the GitHub-flavored markdown plugin to parse
// strikethoughs and tables
turndownService
@@ -32,6 +31,7 @@ turndownService
return "\n";
},
});
interface ImportableFile {
type: string;
getMarkdown: (file: any) => Promise<string>;

View File

@@ -1,3 +1,4 @@
import { Transaction } from "sequelize";
import { sequelize } from "@server/database/sequelize";
import Logger from "@server/logging/logger";
import {
@@ -31,8 +32,7 @@ export default async function teamPermanentDeleter(team: Team) {
`Permanently deleting team ${team.name} (${team.id})`
);
const teamId = team.id;
// @ts-expect-error ts-migrate(7034) FIXME: Variable 'transaction' implicitly has type 'any' i... Remove this comment to see the full error message
let transaction;
let transaction!: Transaction;
try {
transaction = await sequelize.transaction();
@@ -54,7 +54,6 @@ export default async function teamPermanentDeleter(team: Team) {
await Promise.all(
attachments.map((attachment) =>
attachment.destroy({
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'transaction' implicitly has an 'any' typ... Remove this comment to see the full error message
transaction,
})
)
@@ -78,7 +77,6 @@ export default async function teamPermanentDeleter(team: Team) {
userId: userIds,
},
force: true,
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'transaction' implicitly has an 'any' typ... Remove this comment to see the full error message
transaction,
});
await ApiKey.destroy({
@@ -86,7 +84,6 @@ export default async function teamPermanentDeleter(team: Team) {
userId: userIds,
},
force: true,
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'transaction' implicitly has an 'any' typ... Remove this comment to see the full error message
transaction,
});
}

View File

@@ -343,8 +343,7 @@ describe("#membershipUserIds", () => {
// Make 6 users
const users = await Promise.all(
Array(6)
// @ts-expect-error ts-migrate(2554) FIXME: Expected 1-3 arguments, but got 0.
.fill()
.fill(undefined)
.map(() =>
buildUser({
teamId,

View File

@@ -353,7 +353,7 @@ class Collection extends ParanoidModel {
}
getDocumentTree = function (documentId: string): NavigationNode {
let result: NavigationNode;
let result!: NavigationNode;
const loopChildren = (documents: NavigationNode[]) => {
if (result) {
@@ -375,7 +375,6 @@ class Collection extends ParanoidModel {
loopChildren(this.documentStructure);
// @ts-expect-error used before undefined
return result;
};
@@ -479,7 +478,7 @@ class Collection extends ParanoidModel {
};
getDocumentParents = function (documentId: string): string[] | void {
let result: string[];
let result!: string[];
const loopChildren = (documents: NavigationNode[], path: string[] = []) => {
if (result) {
@@ -499,7 +498,6 @@ class Collection extends ParanoidModel {
loopChildren(this.documentStructure);
}
// @ts-expect-error used before undefined
return result;
};

View File

@@ -3,50 +3,42 @@ import { User } from "@server/models";
type Options = {
includeDetails?: boolean;
};
type UserPresentation = {
id: string;
name: string;
avatarUrl: string | null | undefined;
email?: string;
createdAt: Date;
lastActiveAt: Date | null;
color: string;
isAdmin: boolean;
isSuspended: boolean;
isViewer: boolean;
language: string;
email?: string | null;
language?: string;
};
export default (
user: User,
options: Options = {}
): UserPresentation | null | undefined => {
const userData = {};
// @ts-expect-error ts-migrate(2339) FIXME: Property 'id' does not exist on type '{}'.
userData.id = user.id;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'createdAt' does not exist on type '{}'.
userData.createdAt = user.createdAt;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'name' does not exist on type '{}'.
userData.name = user.name;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'color' does not exist on type '{}'.
userData.color = user.color;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'isAdmin' does not exist on type '{}'.
userData.isAdmin = user.isAdmin;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'isViewer' does not exist on type '{}'.
userData.isViewer = user.isViewer;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'isSuspended' does not exist on type '{}'... Remove this comment to see the full error message
userData.isSuspended = user.isSuspended;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'avatarUrl' does not exist on type '{}'.
userData.avatarUrl = user.avatarUrl;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'lastActiveAt' does not exist on type '{}... Remove this comment to see the full error message
userData.lastActiveAt = user.lastActiveAt;
const userData: UserPresentation = {
id: user.id,
name: user.name,
avatarUrl: user.avatarUrl,
color: user.color,
isAdmin: user.isAdmin,
isSuspended: user.isSuspended,
isViewer: user.isViewer,
createdAt: user.createdAt,
lastActiveAt: user.lastActiveAt,
};
if (options.includeDetails) {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'email' does not exist on type '{}'.
userData.email = user.email;
// @ts-expect-error ts-migrate(2339) FIXME: Property 'language' does not exist on type '{}'.
userData.language =
user.language || process.env.DEFAULT_LANGUAGE || "en_US";
}
// @ts-expect-error ts-migrate(2740) FIXME: Type '{}' is missing the following properties from... Remove this comment to see the full error message
return userData;
};

View File

@@ -33,7 +33,7 @@ export default class NotificationsProcessor {
async documentUpdated(event: DocumentEvent | RevisionEvent) {
// never send notifications when batch importing documents
// @ts-expect-error ts-migrate(2339) FIXME: Property 'data' does not exist on type 'DocumentEv... Remove this comment to see the full error message
if (event.data && event.data.source === "import") return;
if (event.data?.source === "import") return;
const [document, team] = await Promise.all([
Document.findByPk(event.documentId),
Team.findByPk(event.teamId),

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import Attachment from "@server/models/Attachment";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import { buildUser, buildTeam } from "@server/test/factories";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { v4 as uuidv4 } from "uuid";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { Document, CollectionUser, CollectionGroup } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import {
Document,

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import { buildEvent, buildUser } from "@server/test/factories";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { Collection, User, Event, FileOperation } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { Event } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { IntegrationAuthentication, SearchQuery } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import { flushdb } from "@server/test/support";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import {

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import { flushdb, seed } from "@server/test/support";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { Revision } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { CollectionUser } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import { flushdb, seed } from "@server/test/support";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import { buildTeam, buildAdmin, buildUser } from "@server/test/factories";

View File

@@ -1,5 +1,4 @@
import { subDays } from "date-fns";
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { Document, FileOperation } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { View, CollectionUser } from "@server/models";
import webService from "@server/services/web";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import webService from "@server/services/web";
import { buildUser, buildCollection } from "@server/test/factories";

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import mailer from "@server/mailer";
import webService from "@server/services/web";

View File

@@ -31,8 +31,7 @@ router.post("email", errorHandling(), async (ctx) => {
});
if (users.length) {
// @ts-expect-error ts-migrate(7034) FIXME: Variable 'team' implicitly has type 'any' in some ... Remove this comment to see the full error message
let team;
let team!: Team | null;
if (isCustomDomain(ctx.request.hostname)) {
team = await Team.scope("withAuthenticationProviders").findOne({
@@ -58,7 +57,6 @@ router.post("email", errorHandling(), async (ctx) => {
// If there are multiple users with this email address then give precedence
// to the one that is active on this subdomain/domain (if any)
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'user' implicitly has an 'any' type.
let user = users.find((user) => team && user.teamId === team.id);
// A user was found for the email address, but they don't belong to the team
@@ -132,8 +130,7 @@ router.get("email.callback", async (ctx) => {
assertPresent(token, "token is required");
try {
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'string | string[] | undefined' i... Remove this comment to see the full error message
const user = await getUserForEmailSigninToken(token);
const user = await getUserForEmailSigninToken(token as string);
if (!user.team.guestSignin) {
return ctx.redirect("/?notice=auth-error");
@@ -153,6 +150,7 @@ router.get("email.callback", async (ctx) => {
await user.update({
lastActiveAt: new Date(),
});
// set cookies on response and redirect to team subdomain
await signIn(ctx, user, user.team, "email", false, false);
} catch (err) {

View File

@@ -1,3 +1,4 @@
import Router from "koa-router";
import { signin } from "@shared/utils/routeHelpers";
import { requireDirectory } from "@server/utils/fs";
@@ -6,7 +7,7 @@ interface AuthenicationProvider {
name: string;
enabled: boolean;
authUrl: string;
router: any;
router: Router;
}
const providers: AuthenicationProvider[] = [];

View File

@@ -1,4 +1,3 @@
// @ts-expect-error ts-migrate(7016) FIXME: Could not find a declaration file for module 'fetc... Remove this comment to see the full error message
import TestServer from "fetch-test-server";
import { buildShare, buildDocument } from "@server/test/factories";
import { flushdb } from "@server/test/support";

View File

@@ -47,8 +47,7 @@ export default function init() {
name: event.name,
modelId: event.modelId,
});
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'error' implicitly has an 'any' type.
processor.on(event).catch((error) => {
processor.on(event).catch((error: Error) => {
Logger.error(
`Error processing ${event.name} in ${event.service}`,
error,

View File

@@ -8,26 +8,14 @@ declare module "formidable/lib/file";
declare module "socket.io-client";
declare module "@tommoor/remove-markdown" {
export default function removeMarkdown(
text: string,
options?: {
stripHTML: boolean;
}
): string;
}
declare module "socket.io-redis" {
import { Redis } from "ioredis";
type Config = {
pubClient: Redis;
subClient: Redis;
};
const socketRedisAdapter: (config: Config) => void;
export = socketRedisAdapter;
}
declare module "oy-vey";
declare module "fetch-test-server";
declare module "joplin-turndown-plugin-gfm" {
import { Plugin } from "turndown";
export const strikethrough: Plugin;
export const tables: Plugin;
}

12
server/typings/socketio-redis.d.ts vendored Normal file
View File

@@ -0,0 +1,12 @@
declare module "socket.io-redis" {
import { Redis } from "ioredis";
type Config = {
pubClient: Redis;
subClient: Redis;
};
const socketRedisAdapter: (config: Config) => void;
export = socketRedisAdapter;
}

View File

@@ -0,0 +1,8 @@
declare module "@tommoor/remove-markdown" {
export default function removeMarkdown(
text: string,
options?: {
stripHTML: boolean;
}
): string;
}

View File

@@ -20,7 +20,6 @@ export default async function collectionIndexing(teamId: string) {
sortableCollections = naturalSort(
sortableCollections,
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '(collection: any) => any' is not... Remove this comment to see the full error message
(collection) => collection[0].name
);

View File

@@ -8,8 +8,8 @@ export function getCookieDomain(domain: string) {
export function isCustomDomain(hostname: string) {
const parsed = parseDomain(hostname);
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'string | undefined' is not assig... Remove this comment to see the full error message
const main = parseDomain(process.env.URL);
return (
parsed && main && (main.domain !== parsed.domain || main.tld !== parsed.tld)
);

View File

@@ -1,16 +1,14 @@
import { Node } from "prosemirror-model";
import { parser } from "rich-markdown-editor";
export default function parseDocumentIds(text: string): string[] {
const value = parser.parse(text);
// @ts-expect-error ts-migrate(7034) FIXME: Variable 'links' implicitly has type 'any[]' in so... Remove this comment to see the full error message
const links = [];
const links: string[] = [];
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'node' implicitly has an 'any' type.
function findLinks(node) {
function findLinks(node: Node) {
// get text nodes
if (node.type.name === "text") {
// get marks for text nodes
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'mark' implicitly has an 'any' type.
node.marks.forEach((mark) => {
// any of the marks links?
if (mark.type.name === "link") {
@@ -22,7 +20,6 @@ export default function parseDocumentIds(text: string): string[] {
const lastToken = tokens[tokens.length - 1];
// don't return the same link more than once
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'links' implicitly has an 'any[]' type.
if (!links.includes(lastToken)) {
links.push(lastToken);
}
@@ -39,6 +36,5 @@ export default function parseDocumentIds(text: string): string[] {
}
findLinks(value);
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'links' implicitly has an 'any[]' type.
return links;
}

View File

@@ -1,14 +1,12 @@
import { Node } from "prosemirror-model";
import { parser } from "rich-markdown-editor";
export default function parseImages(text: string): string[] {
const value = parser.parse(text);
// @ts-expect-error ts-migrate(7034) FIXME: Variable 'images' implicitly has type 'any[]' in s... Remove this comment to see the full error message
const images = [];
const images: string[] = [];
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'node' implicitly has an 'any' type.
function findImages(node) {
function findImages(node: Node) {
if (node.type.name === "image") {
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'images' implicitly has an 'any[]' type.
if (!images.includes(node.attrs.src)) {
images.push(node.attrs.src);
}
@@ -24,6 +22,5 @@ export default function parseImages(text: string): string[] {
}
findImages(value);
// @ts-expect-error ts-migrate(7005) FIXME: Variable 'images' implicitly has an 'any[]' type.
return images;
}

View File

@@ -15,8 +15,7 @@ describe("Miro", () => {
test("to extract the domain as part of the match for later use", () => {
expect(
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
"https://realtimeboard.com/app/board/o9J_k0fwiss=".match(match)[1]
"https://realtimeboard.com/app/board/o9J_k0fwiss=".match(match)?.[1]
).toBe("realtimeboard");
});

View File

@@ -98,10 +98,7 @@ describe("#parseDomain", () => {
});
it("should return null if the given value is not a string", () => {
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'undefined' is not assignable to ... Remove this comment to see the full error message
expect(parseDomain(undefined)).toBe(null);
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '{}' is not assignable to paramet... Remove this comment to see the full error message
expect(parseDomain({})).toBe(null);
expect(parseDomain("")).toBe(null);
});

View File

@@ -9,9 +9,10 @@ type Domain = {
// we originally used the parse-domain npm module however this includes
// a large list of possible TLD's which increase the size of the bundle
// unnecessarily for our usecase of trusted input.
export function parseDomain(url: string): Domain | null | undefined {
export function parseDomain(url?: string): Domain | null | undefined {
if (typeof url !== "string") return null;
if (url === "") return null;
// strip extermeties and whitespace from input
const normalizedDomain = trim(url.replace(/(https?:)?\/\//, ""));
const parts = normalizedDomain.split(".");

View File

@@ -38,7 +38,6 @@ describe("#naturalSort", () => {
name: "Mark",
},
];
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type '(item: any) => any' is not assig... Remove this comment to see the full error message
expect(naturalSort(items, (item) => item.name)).toEqual([
{
name: "Joan",

View File

@@ -27,7 +27,7 @@ function getSortByField<T>(
function naturalSortBy<T>(
items: T[],
key: string | (() => string),
key: string | ((item: T) => string),
sortOptions?: NaturalSortOptions
): T[] {
if (!items) return [];

View File

@@ -1,6 +1,7 @@
import path from "path";
// @ts-expect-error ts-migrate(2724) FIXME: '"jszip"' has no exported member named 'ZipObject'... Remove this comment to see the full error message
import JSZip, { ZipObject } from "jszip";
import JSZip, { JSZipObject } from "jszip";
type ItemType = "collection" | "document" | "attachment";
export type Item = {
path: string;
@@ -8,9 +9,8 @@ export type Item = {
name: string;
depth: number;
metadata: Record<string, any>;
type: "collection" | "document" | "attachment";
item: ZipObject;
type: ItemType;
item: JSZipObject;
};
export async function parseOutlineExport(
@@ -47,7 +47,7 @@ export async function parseOutlineExport(
);
}
let type;
let type: ItemType | undefined;
if (depth === 0 && item.dir && name) {
type = "collection";
@@ -70,7 +70,6 @@ export async function parseOutlineExport(
dir,
name,
depth,
// @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type '"collecti... Remove this comment to see the full error message
type,
metadata,
item,

View File

@@ -3170,10 +3170,10 @@
"@types/history" "*"
"@types/react" "*"
"@types/react-table@^7.7.8":
version "7.7.8"
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.8.tgz#b1aa5fb7a54432969262d2306b87fdbb9a5ee647"
integrity sha512-OMhbPlf+uUGte3M1WdArEKeBkyQ1XJxKvFYs+o1dGGGyaSVIqxPPQmBZ6Skkw0V9y0F/kOY7rnTD8r9GbfpBOg==
"@types/react-table@^7.7.9":
version "7.7.9"
resolved "https://registry.yarnpkg.com/@types/react-table/-/react-table-7.7.9.tgz#ea82875775fc6ee71a28408dcc039396ae067c92"
integrity sha512-ejP/J20Zlj9VmuLh73YgYkW2xOSFTW39G43rPH93M4mYWdMmqv66lCCr+axZpkdtlNLGjvMG2CwzT4S6abaeGQ==
dependencies:
"@types/react" "*"