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!
This commit is contained in:
Guangcong Luo 2020-08-09 08:04:54 -05:00
parent 188111c316
commit a315c93836
10 changed files with 22 additions and 24 deletions

2
build
View File

@ -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");
}

View File

@ -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"
}
}

View File

@ -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',

View File

@ -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> | string | null | void;

View File

@ -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},

View File

@ -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.

View File

@ -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;

View File

@ -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

View File

@ -4,7 +4,7 @@ interface Match {
result?: string;
}
type TournamentPlayer = import('./index').TournamentPlayer;
import type {TournamentPlayer} from './index';
export class RoundRobin {
readonly name: string;

View File

@ -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,