3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-10 12:25:02 +00:00

Turn on strict TS compilation. Fix up and tweak types accordingly.

This commit is contained in:
Dragory 2020-11-09 20:03:57 +02:00
parent 690955a399
commit 629002b8d9
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
172 changed files with 720 additions and 534 deletions

View file

@ -26,7 +26,7 @@ export function asyncFilter<T>(
arr: T[],
callback: (element: T, index: number, array: T[]) => Awaitable<boolean>,
): Promise<T[]> {
return asyncReduce(
return asyncReduce<T, T[]>(
arr,
async (newArray, element, i, _arr) => {
if (await callback(element, i, _arr)) {
@ -43,7 +43,7 @@ export function asyncMap<T, V>(
arr: T[],
callback: (currentValue: T, index: number, array: T[]) => Awaitable<V>,
): Promise<V[]> {
return asyncReduce(
return asyncReduce<T, V[]>(
arr,
async (newArray, element, i, _arr) => {
newArray.push(await callback(element, i, _arr));

View file

@ -16,13 +16,13 @@ export function canAssignRole(guild: Guild, member: Member, roleId: string) {
return false;
}
const memberRoles = member.roles.map(_roleId => guild.roles.get(_roleId));
const highestRoleWithManageRoles: Role = memberRoles.reduce((highest, role) => {
const memberRoles = member.roles.map(_roleId => guild.roles.get(_roleId)!);
const highestRoleWithManageRoles = memberRoles.reduce<Role | null>((highest, role) => {
if (!hasDiscordPermissions(role.permissions, Constants.Permissions.manageRoles)) return highest;
if (highest == null) return role;
if (role.position > highest.position) return role;
return highest;
}, null);
return highestRoleWithManageRoles.position > targetRole.position;
return highestRoleWithManageRoles && highestRoleWithManageRoles.position > targetRole.position;
}

View file

@ -19,7 +19,7 @@ for (const key in Constants.Permissions) {
* @param permissions Bitmask of permissions to get the names for
*/
export function getPermissionNames(permissions: number | bigint): string[] {
const permissionNames = [];
const permissionNames: string[] = [];
for (const [permissionNumber, permissionName] of permissionNumberToName.entries()) {
if (BigInt(permissions) & permissionNumber) {
permissionNames.push(permissionName);

View file

@ -1,9 +1,10 @@
import { MessageContent, MessageFile, User } from "eris";
import { createChunkedMessage, HOURS, isDiscordRESTError } from "../utils";
import { logger } from "../logger";
import Timeout = NodeJS.Timeout;
let dmsDisabled = false;
let dmsDisabledTimeout = null;
let dmsDisabledTimeout: Timeout;
function disableDMs(duration) {
dmsDisabled = true;

View file

@ -1,2 +1,7 @@
// From https://stackoverflow.com/a/56370310/316944
export type Tail<T extends any[]> = ((...t: T) => void) extends (h: any, ...r: infer R) => void ? R : never;
export declare type WithRequiredProps<T, K extends keyof T> = T &
{
[PK in K]-?: Exclude<T[K], null>;
};