chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously. closes #1282
This commit is contained in:
53
server/presenters/user.ts
Normal file
53
server/presenters/user.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { User } from "@server/models";
|
||||
|
||||
type Options = {
|
||||
includeDetails?: boolean;
|
||||
};
|
||||
type UserPresentation = {
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl: string | null | undefined;
|
||||
email?: string;
|
||||
color: string;
|
||||
isAdmin: boolean;
|
||||
isSuspended: boolean;
|
||||
isViewer: boolean;
|
||||
language: string;
|
||||
};
|
||||
|
||||
export default (
|
||||
// @ts-expect-error ts-migrate(2749) FIXME: 'User' refers to a value, but is being used as a t... Remove this comment to see the full error message
|
||||
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;
|
||||
|
||||
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;
|
||||
};
|
||||
Reference in New Issue
Block a user