Skip to content

Commit

Permalink
refactor: type.ts の any を 適切な型に置き換え
Browse files Browse the repository at this point in the history
Signed-off-by: Umisyo <kusunokisouta@gmail.com>
  • Loading branch information
Umisyo committed Jul 7, 2023
1 parent f76b3ed commit 258aead
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions packages/backend/src/core/activitypub/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type Obj = { [x: string]: any };
import { DriveFile } from '@/models/index.js';

export type Obj = { [x: string]: unknown};
export type ApObject = IObject | string | (IObject | string)[];

export interface IObject {
Expand All @@ -11,14 +13,14 @@ export interface IObject {
cc?: ApObject;
to?: ApObject;
attributedTo?: ApObject;
attachment?: any[];
inReplyTo?: any;
attachment?: IObject[];
inReplyTo?: string | IPost | undefined | null;
replies?: ICollection;
content?: string | null;
startTime?: Date;
endTime?: Date;
icon?: any;
image?: any;
icon?: DriveFile | undefined;
image?: DriveFile | undefined;
url?: ApObject | string;
href?: string;
tag?: IObject | IObject[];
Expand Down Expand Up @@ -138,6 +140,7 @@ interface IQuestionChoice {
replies?: ICollection;
_misskey_votes?: number;
}

export interface ITombstone extends IObject {
type: 'Tombstone';
formerType?: string;
Expand Down Expand Up @@ -225,8 +228,14 @@ export interface IApEmoji extends IObject {
updated: string;
}

export const isEmoji = (object: IObject): object is IApEmoji =>
getApType(object) === 'Emoji' && !Array.isArray(object.icon) && object.icon.url != null;
export const isEmoji = (object: IObject): object is IApEmoji => {
const isTypeEmoji = getApType(object) === 'Emoji';
const hasIcon = 'icon' in object;
const iconIsNotArray = !Array.isArray(object.icon);
const iconHasUrl = object.icon?.url !== null;

return isTypeEmoji && hasIcon && iconIsNotArray && iconHasUrl;
};

export interface IKey extends IObject {
type: 'Key';
Expand Down

0 comments on commit 258aead

Please sign in to comment.