pokemon-showdown/server/chat-plugins
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
..
calculator.js Calculator: Support modulos (#5455) 2019-04-17 22:22:30 +09:30
chat-monitor.js toId -> toID 2019-05-12 17:53:01 -07:00
COMMANDS.md Require object literal method shorthand 2019-02-11 18:14:09 -06:00
daily-spotlight.js toId -> toID 2019-05-12 17:53:01 -07:00
datasearch.js TypeScript: export default 2019-05-14 20:33:33 +10:00
hangman.js toId -> toID 2019-05-12 17:53:01 -07:00
helptickets.js toId -> toID 2019-05-12 17:53:01 -07:00
info.js Refactor DNSBL -> IPTools 2019-05-14 10:57:08 +10:00
jeopardy.js toId -> toID 2019-05-12 17:53:01 -07:00
mafia-data.js Mafia: Shorten Idea Timer and Correct IDEA Rolelists (#5357) 2019-03-28 08:54:09 -04:00
mafia.js toId -> toID 2019-05-12 17:53:01 -07:00
modlog.js TypeScript: export default 2019-05-14 20:33:33 +10:00
othermetas.js toId -> toID 2019-05-12 17:53:01 -07:00
poll.js Change forEach to for...of (#5269) 2019-03-08 11:24:58 -06:00
room-events.js toId -> toID 2019-05-12 17:53:01 -07:00
room-faqs.js toId -> toID 2019-05-12 17:53:01 -07:00
roomsettings.js toId -> toID 2019-05-12 17:53:01 -07:00
scavenger-games.js toId -> toID 2019-05-12 17:53:01 -07:00
scavengers.js toId -> toID 2019-05-12 17:53:01 -07:00
tcgtabletop.js TCG: Refactor net functions 2019-03-24 02:24:30 -05:00
thecafe.js toId -> toID 2019-05-12 17:53:01 -07:00
thing-of-the-day.js toId -> toID 2019-05-12 17:53:01 -07:00
trivia.js toId -> toID 2019-05-12 17:53:01 -07:00
uno.js toId -> toID 2019-05-12 17:53:01 -07:00
wifi.js toId -> toID 2019-05-12 17:53:01 -07:00