pokemon-showdown/data
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
..
mods toId -> toID 2019-05-12 17:53:01 -07:00
abilities.js Battle toJSON/fromJSON (#5427) 2019-04-30 14:48:27 +12:00
aliases.js Add alias for Regenerator (#5396) 2019-04-02 15:39:09 +04:00
bss-factory-sets.json Battle Factory: Add tests for EVs, learnsets, and natures (#5397) 2019-04-13 04:40:00 +09:30
factory-sets.json Update Battle Factory OU, UU, and NU (#5351) 2019-04-15 20:56:53 +04:00
formats-data.js Random Battle updates 2019-05-12 18:31:56 +04:00
items.js Redo Endless Battle Clause with a new specification (#5472) 2019-05-07 11:18:06 +09:30
learnsets.js Add new event Pokemon 2019-03-28 08:32:45 -04:00
moves.js toId -> toID 2019-05-12 17:53:01 -07:00
pokedex.js CAP: Nerf Necturna (#5257) 2019-03-05 19:01:45 -06:00
random-teams.js TypeScript: export default 2019-05-14 20:33:33 +10:00
rulesets.js Update reference to EBC spec 2019-05-13 16:25:49 -07:00
scripts.js toId -> toID 2019-05-12 17:53:01 -07:00
statuses.js Move -mustrecharge message to onStart (#5488) 2019-05-08 16:39:56 -04:00
typechart.js Typescript data/ and config/formats (#4513) 2018-03-26 09:50:51 -05:00