pokemon-showdown/server
Guangcong Luo 87ef0cd5c4 TypeScript: export default
I'm currently pretty annoyed at TypeScript and TC39 for default exports
being a mess.

The goal here is to be able to type

    import Dex from './dex';

instead of any of

    import Dex = require('./dex');
    import {Dex} from './dex';
    import * as Dex from './dex';

This part involves a significant amount of struggle.

First, you can't automatically package up all your exports as your
default export. This leads to extremely un-DRY code, like in sim/index:

    export {
        Pokemon,
        Side,
        Battle,
        PRNG,
        Dex,
        TeamValidator,

        BattleStream,
    };

    export const Sim = {
        Pokemon,
        Side,
        Battle,
        PRNG,
        Dex,
        TeamValidator,

        BattleStream,
    };

(Both of these exports would be entirely unnecessary if you could just
automatically declare the file's exports as a default namespace.)

Second, a default export can't easily be a namespace. And TypeScript
doesn't allow types to exist in objects. Take the example from earlier:

    export const Sim = {
        Pokemon,
    };

If we were to try to use it:

    import Sim from './sim';
    let pokemon: Sim.Pokemon;

you'll get this error:

    Cannot find namespace 'Sim'. ts(2503)

You can, of course, fix this by making Sim a namespace:

    const PokemonT = Pokemon;
    type PokemonT = Pokemon;
    export namespace Sim {
        export const Pokemon = PokemonT;
        type Pokemon = PokemonT;
    }

But this quickly gets ridiculous the more classes you try to export.

You'd think there'd be a better way to do this. But I, at least,
haven't found one.
2019-05-14 20:33:33 +10:00
..
chat-plugins TypeScript: export default 2019-05-14 20:33:33 +10:00
static Move server code to server/ 2019-02-03 16:07:06 -06:00
tournaments toId -> toID 2019-05-12 17:53:01 -07:00
chat-commands.js TypeScript: export default 2019-05-14 20:33:33 +10:00
chat-formatter.ts TypeScript: export default 2019-05-14 20:33:33 +10:00
chat.js toId -> toID 2019-05-12 17:53:01 -07:00
global.d.ts TypeScript: export default 2019-05-14 20:33:33 +10:00
globals.ts TypeScript: export default 2019-05-14 20:33:33 +10:00
index.js TypeScript: export default 2019-05-14 20:33:33 +10:00
ip-tools.ts TypeScript: export default 2019-05-14 20:33:33 +10:00
ladders-local.ts TypeScript: export default 2019-05-14 20:33:33 +10:00
ladders-remote.ts TypeScript: export default 2019-05-14 20:33:33 +10:00
ladders.js TypeScript: export default 2019-05-14 20:33:33 +10:00
loginserver.ts TypeScript: export default 2019-05-14 20:33:33 +10:00
monitor.js TypeScript: export default 2019-05-14 20:33:33 +10:00
punishments.js Refactor DNSBL -> IPTools 2019-05-14 10:57:08 +10:00
room-battle.js RoomBattle: Don't destroy players at end of game 2019-05-14 11:04:34 +10:00
room-game.js Update RoomGame API (#5492) 2019-05-12 12:56:32 +09:30
roomlogs.js toId -> toID 2019-05-12 17:53:01 -07:00
rooms.js toId -> toID 2019-05-12 17:53:01 -07:00
sockets.js TypeScript: export default 2019-05-14 20:33:33 +10:00
team-validator-async.js TypeScript: export default 2019-05-14 20:33:33 +10:00
users.js toId -> toID 2019-05-12 17:53:01 -07:00
verifier.ts Typescript server/verifier.js (#5482) 2019-05-07 14:09:01 +09:30