Skip to content

Commit

Permalink
Change type imports to explicit TS syntax (#639)
Browse files Browse the repository at this point in the history
I'm mainly interested in getting this merged to eventually run `damage-calc` under bun (they apparently don't support importing types without doing this oven-sh/bun#7384 (comment))

The changes are mostly generated with the new eslint rule + `eslint --fix .` (with some manual fixes after)

https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export
  • Loading branch information
singiamtel authored Aug 8, 2024
1 parent 003fc34 commit a07db78
Show file tree
Hide file tree
Showing 31 changed files with 78 additions and 77 deletions.
3 changes: 2 additions & 1 deletion calc/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@typescript-eslint/no-unused-vars": "off",
"jest/no-standalone-expect": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"jest/no-conditional-expect": "off"
"jest/no-conditional-expect": "off",
"@typescript-eslint/consistent-type-imports": "error"
}
}
8 changes: 4 additions & 4 deletions calc/src/calc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Field} from './field';
import {Generation} from './data/interface';
import {Move} from './move';
import {Pokemon} from './pokemon';
import {Result} from './result';
import type {Generation} from './data/interface';
import type {Move} from './move';
import type {Pokemon} from './pokemon';
import type {Result} from './result';

import {calculateRBYGSC} from './mechanics/gen12';
import {calculateADV} from './mechanics/gen3';
Expand Down
2 changes: 1 addition & 1 deletion calc/src/data/abilities.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as I from './interface';
import type * as I from './interface';
import {toID} from '../util';

const RBY: string[] = [];
Expand Down
2 changes: 1 addition & 1 deletion calc/src/data/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as I from './interface';
import type * as I from './interface';

import {Abilities} from './abilities';
import {Items} from './items';
Expand Down
2 changes: 1 addition & 1 deletion calc/src/data/items.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as I from './interface';
import type * as I from './interface';
import {toID} from '../util';

const RBY: string[] = [];
Expand Down
4 changes: 2 additions & 2 deletions calc/src/data/moves.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as I from '../data/interface';
import {toID, DeepPartial, assignWithout, extend} from '../util';
import type * as I from '../data/interface';
import {type DeepPartial, toID, assignWithout, extend} from '../util';

export interface MoveData {
readonly name?: string;
Expand Down
2 changes: 1 addition & 1 deletion calc/src/data/natures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as I from './interface';
import type * as I from './interface';
import {toID} from '../util';

export const NATURES: {[name: string]: [I.StatID, I.StatID]} = {
Expand Down
4 changes: 2 additions & 2 deletions calc/src/data/species.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as I from './interface';
import {toID, extend, DeepPartial, assignWithout} from '../util';
import type * as I from './interface';
import {type DeepPartial, toID, extend, assignWithout} from '../util';

export interface SpeciesData {
readonly types: [I.TypeName] | [I.TypeName, I.TypeName];
Expand Down
2 changes: 1 addition & 1 deletion calc/src/data/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as I from './interface';
import type * as I from './interface';
import {toID, extend} from '../util';

export type TypeChart = {
Expand Down
10 changes: 5 additions & 5 deletions calc/src/desc.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Generation, Weather, Terrain, TypeName, ID} from './data/interface';
import {Field, Side} from './field';
import {Move} from './move';
import {Pokemon} from './pokemon';
import {Damage, damageRange} from './result';
import type {Generation, Weather, Terrain, TypeName, ID} from './data/interface';
import type {Field, Side} from './field';
import type {Move} from './move';
import type {Pokemon} from './pokemon';
import {type Damage, damageRange} from './result';
import {error} from './util';
// NOTE: This needs to come last to simplify bundling
import {isGrounded} from './mechanics/util';
Expand Down
4 changes: 2 additions & 2 deletions calc/src/field.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {State} from './state';
import {GameType, Weather, Terrain} from './data/interface';
import type {State} from './state';
import type {GameType, Weather, Terrain} from './data/interface';

export class Field implements State.Field {
gameType: GameType;
Expand Down
8 changes: 4 additions & 4 deletions calc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
// that the correct loading order being followed.

import {Generations} from './data';
import {State} from './state';
import * as I from './data/interface';
import type {State} from './state';
import type * as I from './data/interface';
import * as A from './adaptable';

// The loading strategy outlined in the comment above breaks in the browser when we start reusing
Expand Down Expand Up @@ -142,10 +142,10 @@ export function calcStat(

export {Field, Side} from './field';
export {Result} from './result';
export {GenerationNum, StatsTable, StatID} from './data/interface';
export {type GenerationNum, type StatsTable, type StatID} from './data/interface';
export {Generations} from './data/index';
export {toID} from './util';
export {State} from './state';
export {type State} from './state';

export {ABILITIES} from './data/abilities';
export {ITEMS, MEGA_STONES} from './data/items';
Expand Down
2 changes: 1 addition & 1 deletion calc/src/items.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Generation, TypeName, StatID} from './data/interface';
import type {Generation, TypeName, StatID} from './data/interface';
import {toID} from './util';

export const SEED_BOOSTED_STAT: {[item: string]: StatID} = {
Expand Down
10 changes: 5 additions & 5 deletions calc/src/mechanics/gen12.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Generation} from '../data/interface';
import type {Generation} from '../data/interface';
import {getItemBoostType} from '../items';
import {RawDesc} from '../desc';
import {Field} from '../field';
import {Move} from '../move';
import {Pokemon} from '../pokemon';
import type {RawDesc} from '../desc';
import type {Field} from '../field';
import type {Move} from '../move';
import type {Pokemon} from '../pokemon';
import {Result} from '../result';
import {computeFinalStats, getMoveEffectiveness, handleFixedDamageMoves} from './util';

Expand Down
10 changes: 5 additions & 5 deletions calc/src/mechanics/gen3.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Generation} from '../data/interface';
import type {Generation} from '../data/interface';
import {getItemBoostType} from '../items';
import {RawDesc} from '../desc';
import {Pokemon} from '../pokemon';
import {Move} from '../move';
import {Field} from '../field';
import type {RawDesc} from '../desc';
import type {Pokemon} from '../pokemon';
import type {Move} from '../move';
import type {Field} from '../field';
import {Result} from '../result';
import {
getModifiedStat,
Expand Down
10 changes: 5 additions & 5 deletions calc/src/mechanics/gen4.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {Generation, AbilityName} from '../data/interface';
import type {Generation, AbilityName} from '../data/interface';
import {getItemBoostType, getNaturalGift, getFlingPower, getBerryResistType} from '../items';
import {RawDesc} from '../desc';
import {Field} from '../field';
import {Move} from '../move';
import {Pokemon} from '../pokemon';
import type {RawDesc} from '../desc';
import type {Field} from '../field';
import type {Move} from '../move';
import type {Pokemon} from '../pokemon';
import {Result} from '../result';
import {
getModifiedStat,
Expand Down
10 changes: 5 additions & 5 deletions calc/src/mechanics/gen56.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Generation, AbilityName} from '../data/interface';
import type {Generation, AbilityName} from '../data/interface';
import {toID} from '../util';
import {
getItemBoostType,
Expand All @@ -7,10 +7,10 @@ import {
getBerryResistType,
getTechnoBlast,
} from '../items';
import {RawDesc} from '../desc';
import {Field} from '../field';
import {Move} from '../move';
import {Pokemon} from '../pokemon';
import type {RawDesc} from '../desc';
import type {Field} from '../field';
import type {Move} from '../move';
import type {Pokemon} from '../pokemon';
import {Result} from '../result';
import {
chainMods,
Expand Down
10 changes: 5 additions & 5 deletions calc/src/mechanics/gen789.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Generation, AbilityName, StatID, Terrain} from '../data/interface';
import type {Generation, AbilityName, StatID, Terrain} from '../data/interface';
import {toID} from '../util';
import {
getBerryResistType,
Expand All @@ -9,10 +9,10 @@ import {
getTechnoBlast,
SEED_BOOSTED_STAT,
} from '../items';
import {RawDesc} from '../desc';
import {Field} from '../field';
import {Move} from '../move';
import {Pokemon} from '../pokemon';
import type {RawDesc} from '../desc';
import type {Field} from '../field';
import type {Move} from '../move';
import type {Pokemon} from '../pokemon';
import {Result} from '../result';
import {
chainMods,
Expand Down
10 changes: 5 additions & 5 deletions calc/src/mechanics/util.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {
import type {
Generation,
ID,
ItemName,
Expand All @@ -11,11 +11,11 @@ import {
Weather,
} from '../data/interface';
import {toID} from '../util';
import {Field, Side} from '../field';
import {Move} from '../move';
import {Pokemon} from '../pokemon';
import type {Field, Side} from '../field';
import type {Move} from '../move';
import type {Pokemon} from '../pokemon';
import {Stats} from '../stats';
import {RawDesc} from '../desc';
import type {RawDesc} from '../desc';

const EV_ITEMS = [
'Macho Brace',
Expand Down
4 changes: 2 additions & 2 deletions calc/src/move.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as I from './data/interface';
import {State} from './state';
import type * as I from './data/interface';
import type {State} from './state';
import {toID, extend} from './util';

const SPECIAL = ['Fire', 'Water', 'Grass', 'Electric', 'Ice', 'Psychic', 'Dark', 'Dragon'];
Expand Down
4 changes: 2 additions & 2 deletions calc/src/pokemon.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as I from './data/interface';
import type * as I from './data/interface';
import {Stats} from './stats';
import {toID, extend, assignWithout} from './util';
import {State} from './state';
import type {State} from './state';

const STATS = ['hp', 'atk', 'def', 'spa', 'spd', 'spe'] as I.StatID[];
const SPC = new Set(['spc']);
Expand Down
10 changes: 5 additions & 5 deletions calc/src/result.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {RawDesc, display, displayMove, getRecovery, getRecoil, getKOChance} from './desc';
import {Generation} from './data/interface';
import {Field} from './field';
import {Move} from './move';
import {Pokemon} from './pokemon';
import {type RawDesc, display, displayMove, getRecovery, getRecoil, getKOChance} from './desc';
import type {Generation} from './data/interface';
import type {Field} from './field';
import type {Move} from './move';
import type {Pokemon} from './pokemon';

export type Damage = number | number[] | [number, number] | [number[], number[]];

Expand Down
2 changes: 1 addition & 1 deletion calc/src/state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as I from './data/interface';
import type * as I from './data/interface';

export namespace State {
export interface Pokemon {
Expand Down
2 changes: 1 addition & 1 deletion calc/src/stats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Natures, Generation, TypeName, StatID, StatsTable} from './data/interface';
import type {Natures, Generation, TypeName, StatID, StatsTable} from './data/interface';
import {toID} from './util';

const RBY: Array<StatID | 'spc'> = ['hp', 'atk', 'def', 'spc', 'spe'];
Expand Down
2 changes: 1 addition & 1 deletion calc/src/test/calc.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable max-len */

import {AbilityName, Terrain, Weather} from '../data/interface';
import type {AbilityName, Terrain, Weather} from '../data/interface';
import {inGen, inGens, tests} from './helper';

describe('calc', () => {
Expand Down
2 changes: 1 addition & 1 deletion calc/src/test/data.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {calculate, Pokemon, Move} from '../adaptable';
import * as I from '../data/interface';
import type * as I from '../data/interface';

import * as calc from '../index';
import {Dex} from '@pkmn/dex';
Expand Down
4 changes: 2 additions & 2 deletions calc/src/test/gen.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as I from '../data/interface';
import * as D from '@pkmn/dex';
import type * as I from '../data/interface';
import type * as D from '@pkmn/dex';

export function toID(s: string) {
return ('' + s).toLowerCase().replace(/[^a-z0-9]+/g, '') as I.ID;
Expand Down
6 changes: 3 additions & 3 deletions calc/src/test/helper.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-env jest */

import * as I from '../data/interface';
import {calculate, Pokemon, Move, Result} from '../index';
import {State} from '../state';
import type * as I from '../data/interface';
import {type Result, calculate, Pokemon, Move} from '../index';
import type {State} from '../state';
import {Field, Side} from '../field';

const calc = (gen: I.GenerationNum) => (
Expand Down
2 changes: 1 addition & 1 deletion calc/src/test/pokemon.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Pokemon} from '../index';
import {StatID, MoveName} from '../data/interface';
import type {StatID, MoveName} from '../data/interface';

describe('Pokemon', () => {
test('defaults', () => {
Expand Down
2 changes: 1 addition & 1 deletion calc/src/test/stats.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {Generations} from '../data';
import {GenerationNum, StatsTable, StatID} from '../data/interface';
import type {GenerationNum, StatsTable, StatID} from '../data/interface';
import {Stats} from '../stats';
import {getModifiedStat} from '../mechanics/util';

Expand Down
2 changes: 1 addition & 1 deletion calc/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable eqeqeq, @typescript-eslint/unbound-method, @typescript-eslint/ban-types */
import {ID} from './data/interface';
import type {ID} from './data/interface';

export function toID(text: any): ID {
return ('' + text).toLowerCase().replace(/[^a-z0-9]+/g, '') as ID;
Expand Down

0 comments on commit a07db78

Please sign in to comment.