From a315c93836072d8e92ef3bf2464ff222ca80ade1 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sun, 9 Aug 2020 08:04:54 -0500 Subject: [PATCH] Switch to using `import type` We were previously using `type Foo = import('bar').Foo` which works actually equally well, because sucrase didn't support `import type`, but now it does! --- build | 2 +- package.json | 4 ++-- server/chat-commands/core.ts | 2 +- server/chat.ts | 3 +-- server/config-loader.ts | 3 +-- server/ladders.ts | 2 +- server/rooms.ts | 10 ++++------ server/tournaments/generator-elimination.ts | 2 +- server/tournaments/generator-round-robin.ts | 2 +- server/users.ts | 16 +++++++++------- 10 files changed, 22 insertions(+), 24 deletions(-) diff --git a/build b/build index be5b5bfc82..2ba76d7633 100755 --- a/build +++ b/build @@ -61,7 +61,7 @@ try { var sucraseVersion = require('sucrase').getVersion().split('.'); if ( parseInt(sucraseVersion[0]) < 3 || - (parseInt(sucraseVersion[0]) === 3 && parseInt(sucraseVersion[1]) < 12) + (parseInt(sucraseVersion[0]) === 3 && parseInt(sucraseVersion[1]) < 15) ) { throw new Error("Sucrase version too old"); } diff --git a/package.json b/package.json index b0ba3691bd..1348758545 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "dependencies": { "probe-image-size": "^5.0.0", "sockjs": "0.3.20", - "sucrase": "^3.13.0" + "sucrase": "^3.15.0" }, "optionalDependencies": { "cloud-env": "^0.2.3", @@ -74,6 +74,6 @@ "husky": "^4.2.3", "mocha": "^7.1.1", "smogon": "^1.1.1", - "typescript": "^3.8.3" + "typescript": "^3.9.7" } } diff --git a/server/chat-commands/core.ts b/server/chat-commands/core.ts index 226ecc1022..402cc81f5f 100644 --- a/server/chat-commands/core.ts +++ b/server/chat-commands/core.ts @@ -15,7 +15,7 @@ /* eslint no-else-return: "error" */ import {Utils} from '../../lib/utils'; -type UserSettings = import('../users').User['settings']; +import type {UserSettings} from '../users'; const avatarTable = new Set([ 'aaron', diff --git a/server/chat.ts b/server/chat.ts index 8c6f2d5835..45a48b240c 100644 --- a/server/chat.ts +++ b/server/chat.ts @@ -23,8 +23,7 @@ To reload chat commands: */ -type RoomPermission = import('./user-groups').RoomPermission; -type GlobalPermission = import('./user-groups').GlobalPermission; +import type {RoomPermission, GlobalPermission} from './user-groups'; export type PageHandler = (this: PageContext, query: string[], user: User, connection: Connection) => Promise | string | null | void; diff --git a/server/config-loader.ts b/server/config-loader.ts index f4be199911..814c229a54 100644 --- a/server/config-loader.ts +++ b/server/config-loader.ts @@ -6,8 +6,7 @@ */ import * as defaults from '../config/config-example'; -type GroupInfo = import('./user-groups').GroupInfo; -type EffectiveGroupSymbol = import('./user-groups').EffectiveGroupSymbol; +import type {GroupInfo, EffectiveGroupSymbol} from './user-groups'; export type ConfigType = typeof defaults & { groups: {[symbol: string]: GroupInfo}, diff --git a/server/ladders.ts b/server/ladders.ts index 08ad5c95b2..3a5f28c092 100644 --- a/server/ladders.ts +++ b/server/ladders.ts @@ -16,7 +16,7 @@ const LadderStore: typeof LadderStoreT = (typeof Config === 'object' && Config.r const SECONDS = 1000; const PERIODIC_MATCH_INTERVAL = 60 * SECONDS; -type ChallengeType = import('./room-battle').ChallengeType; +import type {ChallengeType} from './room-battle'; /** * This represents a user's search for a battle under a format. diff --git a/server/rooms.ts b/server/rooms.ts index d83b92b053..11378a9f21 100644 --- a/server/rooms.ts +++ b/server/rooms.ts @@ -118,12 +118,10 @@ export interface RoomSettings { isMultichannel?: boolean; } export type Room = GameRoom | ChatRoom; -type Poll = import('./chat-plugins/poll').Poll; -type Announcement = import('./chat-plugins/announcements').Announcement; -type RoomEvent = import('./chat-plugins/room-events').RoomEvent; -type RoomEventAlias = import('./chat-plugins/room-events').RoomEventAlias; -type RoomEventCategory = import('./chat-plugins/room-events').RoomEventCategory; -type Tournament = import('./tournaments/index').Tournament; +import type {Poll} from './chat-plugins/poll'; +import type {Announcement} from './chat-plugins/announcements'; +import type {RoomEvent, RoomEventAlias, RoomEventCategory} from './chat-plugins/room-events'; +import type {Tournament} from './tournaments/index'; export abstract class BasicRoom { roomid: RoomID; diff --git a/server/tournaments/generator-elimination.ts b/server/tournaments/generator-elimination.ts index e98e319582..09f714ecbd 100644 --- a/server/tournaments/generator-elimination.ts +++ b/server/tournaments/generator-elimination.ts @@ -6,7 +6,7 @@ interface ElimTree { nextLayerLeafNodes: ElimNode[]; } -type TournamentPlayer = import('./index').TournamentPlayer; +import type {TournamentPlayer} from './index'; /** * There are two types of elim nodes, player nodes diff --git a/server/tournaments/generator-round-robin.ts b/server/tournaments/generator-round-robin.ts index ea4a7f4574..7cac17c2d4 100644 --- a/server/tournaments/generator-round-robin.ts +++ b/server/tournaments/generator-round-robin.ts @@ -4,7 +4,7 @@ interface Match { result?: string; } -type TournamentPlayer = import('./index').TournamentPlayer; +import type {TournamentPlayer} from './index'; export class RoundRobin { readonly name: string; diff --git a/server/users.ts b/server/users.ts index 949cc9bc03..6bdb3fed94 100644 --- a/server/users.ts +++ b/server/users.ts @@ -50,7 +50,7 @@ const MINUTES = 60 * 1000; const IDLE_TIMER = 60 * MINUTES; const STAFF_IDLE_TIMER = 30 * MINUTES; -type StreamWorker = import('../lib/process-manager').StreamWorker; +import type {StreamWorker} from '../lib/process-manager'; /********************************************************* * Utility functions @@ -305,6 +305,13 @@ export class Connection { type ChatQueueEntry = [string, RoomID, Connection]; +export interface UserSettings { + blockChallenges: boolean; + blockPMs: boolean | AuthLevel; + ignoreTickets: boolean; + hideBattlesFromTrainerCard: boolean; +} + // User export class User extends Chat.MessageContext { readonly user: User; @@ -341,12 +348,7 @@ export class User extends Chat.MessageContext { lastMatch: string; forcedPublic: string | null; - settings: { - blockChallenges: boolean, - blockPMs: boolean | AuthLevel, - ignoreTickets: boolean, - hideBattlesFromTrainerCard: boolean, - }; + settings: UserSettings; battleSettings: { team: string,