Skip to content

Commit

Permalink
Make global.d.ts less insane
Browse files Browse the repository at this point in the history
  • Loading branch information
stwlam committed Mar 5, 2021
1 parent c1a7913 commit 1c742ff
Show file tree
Hide file tree
Showing 22 changed files with 170 additions and 179 deletions.
7 changes: 2 additions & 5 deletions .betterer.results
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ exports[`stricter compilation`] = {
[329, 28, 23, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ str: AbilityData; dex: AbilityData; con: AbilityData; int: AbilityData; wis: AbilityData; cha: AbilityData; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ str: AbilityData; dex: AbilityData; con: AbilityData; int: AbilityData; wis: AbilityData; cha: AbilityData; }\'.", "1182846011"],
[375, 36, 31, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ acid: string; adamantine: string; alchemical: string; agile: string; artifact: string; attached: string; backstabber: string; backswing: string; bomb: string; brutal: string; chaotic: string; climbing: string; ... 108 more ...; \'modular-b-P-or-s\': string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ acid: string; adamantine: string; alchemical: string; agile: string; artifact: string; attached: string; backstabber: string; backswing: string; bomb: string; brutal: string; chaotic: string; climbing: string; ... 108 more ...; \'modular-b-P-or-s\': string; }\'.", "3601740505"]
],
"src/module/actor/sheet/base.ts:1120150219": [
"src/module/actor/sheet/base.ts:4261615411": [
[78, 19, 6, "Parameter \'traits\' implicitly has an \'any\' type.", "1720055084"],
[99, 69, 19, "Element implicitly has an \'any\' type because expression of type \'any\' can\'t be used to index type \'{ acid: string; bludgeoning: string; cold: string; fire: string; force: string; electricity: string; sonic: string; negative: string; piercing: string; poison: string; positive: string; bleed: string; ... 12 more ...; \'protean anatomy\': string; } | { ...; } | { ...; } | { ...; } | { ...; }\'.", "3465888121"],
[103, 42, 19, "Element implicitly has an \'any\' type because expression of type \'any\' can\'t be used to index type \'{ acid: string; bludgeoning: string; cold: string; fire: string; force: string; electricity: string; sonic: string; negative: string; piercing: string; poison: string; positive: string; bleed: string; ... 12 more ...; \'protean anatomy\': string; } | { ...; } | { ...; } | { ...; } | { ...; }\'.", "3465888121"],
Expand Down Expand Up @@ -738,9 +738,6 @@ exports[`stricter compilation`] = {
[23, 31, 56, "Element implicitly has an \'any\' type because index expression is not of type \'number\'.", "1741159767"],
[25, 31, 56, "Element implicitly has an \'any\' type because index expression is not of type \'number\'.", "645286097"]
],
"src/module/gm/travel/travel-speed-sheet.ts:934936780": [
[298, 25, 4, "Argument of type \'null\' is not assignable to parameter of type \'{} | undefined\'.", "2087897566"]
],
"src/module/item/bulk.ts:3592305284": [
[280, 8, 15, "Type \'string | undefined\' is not assignable to type \'string\'.\\n Type \'undefined\' is not assignable to type \'string\'.", "424545820"],
[283, 8, 19, "Type \'Bulk | undefined\' is not assignable to type \'Bulk\'.\\n Type \'undefined\' is not assignable to type \'Bulk\'.", "4133372623"],
Expand Down Expand Up @@ -1206,7 +1203,7 @@ exports[`stricter compilation`] = {
[218, 18, 3, "Parameter \'val\' implicitly has an \'any\' type.", "193428222"],
[224, 21, 3, "Parameter \'val\' implicitly has an \'any\' type.", "193428222"]
],
"src/module/system/world-clock/index.ts:2279674915": [
"src/module/system/world-clock/index.ts:1853293595": [
[114, 23, 34, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ January: string; February: string; March: string; April: string; May: string; June: string; July: string; August: string; September: string; October: string; November: string; December: string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ January: string; February: string; March: string; April: string; May: string; June: string; July: string; August: string; September: string; October: string; November: string; December: string; }\'.", "2128514067"],
[126, 23, 38, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ Monday: string; Tuesday: string; Wednesday: string; Thursday: string; Friday: string; Saturday: string; Sunday: string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ Monday: string; Tuesday: string; Wednesday: string; Thursday: string; Friday: string; Saturday: string; Sunday: string; }\'.", "1647180819"],
[139, 15, 42, "Element implicitly has an \'any\' type because expression of type \'string\' can\'t be used to index type \'{ One: string; Two: string; Few: string; Other: string; }\'.\\n No index signature with a parameter of type \'string\' was found on type \'{ One: string; Two: string; Few: string; Other: string; }\'.", "837659766"]
Expand Down
12 changes: 8 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
modulePaths: [
'<rootDir>',
'<rootDir>/src',
'<rootDir>/dist',
'<rootDir>/types/foundry-pc-types',
'<rootDir>',
'<rootDir>/src',
'<rootDir>/dist',
'<rootDir>/types/foundry-pc-types',
],
moduleNameMapper: {
'^@utils$': '<rootDir>/src/module/utils.ts',
'^@scripts/(.*)$': '<rootDir>/src/scripts/$1',
},
setupFiles: [
'./tests/setup.ts',
],
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

140 changes: 61 additions & 79 deletions src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,85 +1,67 @@
declare type TranslationsPF2e = typeof import('../static/lang/en.json');
import { WorldClock } from '@system/world-clock';
import { EffectPanel } from '@system/effect-panel';
import { rollActionMacro, rollItemMacro } from '@scripts/init';
import { calculateXP } from '@scripts/macros/xp';
import { launchTravelSheet } from '@scripts/macros/travel/travel-speed-sheet';
import { PF2EActor } from '@actor/actor';
import { PF2EItem } from '@item/item';
import { ConfigPF2e } from '@scripts/config';
import { PF2eSystem } from './module/pf2e-system';
import { PF2ECombat } from './module/combat';
import { PF2Check } from '@system/rolls';
import {
AbilityModifier,
PF2CheckModifier,
PF2Modifier,
PF2ModifierType,
PF2StatisticModifier,
ProficiencyModifier,
} from './module/modifiers';
import { PF2eConditionManager } from './module/conditions';
import { PF2eStatusEffects } from '@scripts/actor/status-effects';
import { DicePF2e } from '@scripts/dice';

declare interface Game {
pf2e: {
actions: { [key: string]: Function };
worldClock?: import('./module/system/world-clock').WorldClock;
effectPanel?: import('./module/system/effect-panel').EffectPanel;
rollItemMacro?: typeof import('./scripts/init').rollItemMacro;
rollActionMacro: typeof import('./scripts/init').rollActionMacro;
gm: {
calculateXP: Function;
launchTravelSheet: Function;
};
};

socket: SocketIO.Socket & {
emit(message: Pick<import('./scripts/socket').SocketEventCallback, 0>): void;
on(event: string, ...message: import('./scripts/socket').SocketEventCallback): void;
};

i18n: Localization & {
readonly translations: Localization['translations'] & DeepPartial<TranslationsPF2e>;
_fallback: Localization['translations'] & TranslationsPF2e;
};
}

declare type ItemTypeMap = {
[K in keyof import('./scripts/config').ConfigPF2e['PF2E']['Item']['entityClasses']]: InstanceType<
import('./scripts/config').ConfigPF2e['PF2E']['Item']['entityClasses'][K]
type ItemTypeMap = {
[K in keyof ConfigPF2e['PF2E']['Item']['entityClasses']]: InstanceType<
ConfigPF2e['PF2E']['Item']['entityClasses'][K]
>[];
};
declare interface Actor {
itemTypes: ItemTypeMap;
}

declare namespace Items {
function registerSheet(
scope: string,
sheetClass: typeof import('@item/sheet/base').ItemSheetPF2e,
options: { types: string[]; makeDefault?: boolean },
): void;
function registerSheet<S extends typeof import('@item/sheet/kit').KitSheetPF2e>(
scope: string,
sheetClass: S,
options: { types: string[]; makeDefault?: boolean },
): void;
function registerSheet<S extends typeof import('@item/sheet/ancestry').AncestrySheetPF2e>(
scope: string,
sheetClass: S,
options: { types: string[]; makeDefault?: boolean },
): void;
function registerSheet<S extends typeof import('@item/sheet/background').BackgroundSheetPF2e>(
scope: string,
sheetClass: S,
options: { types: string[]; makeDefault?: boolean },
): void;
function registerSheet<S extends typeof import('@item/sheet/class').ClassSheetPF2e>(
scope: string,
sheetClass: S,
options: { types: string[]; makeDefault?: boolean },
): void;
}
declare global {
interface Game {
pf2e: {
actions: { [key: string]: Function };
worldClock?: WorldClock;
effectPanel?: EffectPanel;
rollActionMacro: typeof rollActionMacro;
rollItemMacro: typeof rollItemMacro;
gm: {
calculateXP: typeof calculateXP;
launchTravelSheet: typeof launchTravelSheet;
};
};
}

interface Actor {
itemTypes: ItemTypeMap;
}

declare interface Window {
PF2e: import('./module/pf2e-system').PF2eSystem;
DicePF2e: typeof import('./scripts/dice').DicePF2e;
PF2eStatusEffects: typeof import('./scripts/actor/status-effects').PF2eStatusEffects;
PF2eConditionManager: typeof import('./module/conditions').PF2eConditionManager;
PF2ModifierType: typeof import('./module/modifiers').PF2ModifierType;
PF2Modifier: typeof import('./module/modifiers').PF2Modifier;
AbilityModifier: typeof import('./module/modifiers').AbilityModifier;
ProficiencyModifier: typeof import('./module/modifiers').ProficiencyModifier;
PF2StatisticModifier: typeof import('./module/modifiers').PF2StatisticModifier;
PF2CheckModifier: typeof import('./module/modifiers').PF2CheckModifier;
PF2Check: typeof import('./module/system/rolls').PF2Check;
interface Window {
PF2e: PF2eSystem;
DicePF2e: typeof DicePF2e;
PF2eStatusEffects: typeof PF2eStatusEffects;
PF2eConditionManager: typeof PF2eConditionManager;
PF2ModifierType: typeof PF2ModifierType;
PF2Modifier: typeof PF2Modifier;
AbilityModifier: typeof AbilityModifier;
ProficiencyModifier: typeof ProficiencyModifier;
PF2StatisticModifier: typeof PF2StatisticModifier;
PF2CheckModifier: typeof PF2CheckModifier;
PF2Check: typeof PF2Check;
}
const game: Game<PF2EActor, PF2EItem, PF2ECombat>;
const CONFIG: ConfigPF2e;
const canvas: Canvas<PF2EActor>;
let PF2e: PF2eSystem;
const BUILD_MODE: 'development' | 'production';
}
declare const game: Game<
import('./module/actor/actor').PF2EActor,
import('./module/item/item').PF2EItem,
import('./module/combat').PF2ECombat
>;
declare const CONFIG: import('./scripts/config').ConfigPF2e;
declare const canvas: Canvas<import('./module/actor/actor').PF2EActor>;
declare let PF2e: import('./module/pf2e-system').PF2eSystem;
declare const BUILD_MODE: 'development' | 'production';
2 changes: 1 addition & 1 deletion src/module/actor/sheet/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createConsumableFromSpell, SpellConsumableTypes } from '@item/spell-con
import { Spell } from '@item/spell';
import { SpellcastingEntry } from '@item/spellcasting-entry';
import { PF2ECondition, PF2ESpell } from '@item/others';
import { LocalizePF2e } from '@system/localization';
import { LocalizePF2e } from '@system/localize';

/**
* Extend the basic ActorSheet class to do all the PF2e things!
Expand Down
2 changes: 1 addition & 1 deletion src/module/item/sheet/abc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PF2EBackground } from '@item/background';
import { PF2EClass } from '@item/class';
import { PF2EItem } from '@item/item';
import { TraitSelector5e } from '@system/trait-selector';
import { LocalizePF2e } from '@system/localization';
import { LocalizePF2e } from '@system/localize';
import { ABCSheetData } from './data-types';
import { ConfigPF2e } from '@scripts/config';

Expand Down
6 changes: 3 additions & 3 deletions src/module/item/sheet/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { PF2EActor } from '@actor/actor';
import { getPropertySlots } from '../runes';
import { TraitSelector5e } from '@system/trait-selector';
import { LoreDetailsData, MartialData, WeaponData } from '../data-definitions';
import { LocalizePF2e } from '@system/localization';
import { ConfigPF2e } from 'src/scripts/config';
import { LocalizePF2e } from '@system/localize';
import { ConfigPF2e } from '@scripts/config';
import { AESheetData, SheetOptions, SheetSelections } from './data-types';
import { PF2EItem } from '@item/item';
import { PF2RuleElementData } from 'src/module/rules/rules-data-definitions';
Expand Down Expand Up @@ -558,7 +558,7 @@ export class ItemSheetPF2e<ItemType extends PF2EItem> extends ItemSheet<ItemType
});
}

/** @overide */
/** @override */
protected _getSubmitData(updateData: Record<string, unknown> = {}): Record<string, unknown> {
// create the expanded update data object
const fd = new FormDataExtended(this.form, { editors: this.editors });
Expand Down
3 changes: 2 additions & 1 deletion src/module/register-sheets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { KitSheetPF2e } from '@item/sheet/kit';
import { AncestrySheetPF2e } from '@item/sheet/ancestry';
import { BackgroundSheetPF2e } from '@item/sheet/background';
import { ClassSheetPF2e } from '@item/sheet/class';
import { PF2EItem } from '@item/item';

export function registerSheets() {
Items.unregisterSheet('core', ItemSheet);
Items.registerSheet('pf2e', ItemSheetPF2e, {
Items.registerSheet<PF2EItem>('pf2e', ItemSheetPF2e, {
types: [
'weapon',
'melee',
Expand Down
2 changes: 1 addition & 1 deletion src/module/settings/world-clock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DateTime } from 'luxon';
import { LocalizePF2e } from '../system/localization';
import { LocalizePF2e } from '../system/localize';

type SettingsKey = 'dateTheme' | 'timeConvention' | 'playersCanView' | 'syncDarkness' | 'worldCreatedOn';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import * as translationsPF2e from 'static/lang/en.json';

type TranslationsPF2e = Record<string, TranslationDictionaryValue> & typeof translationsPF2e;

export class LocalizePF2e {
private static _translations: typeof game.i18n._fallback;
private static _translations: TranslationsPF2e;

static get translations(): typeof game.i18n._fallback {
static get translations(): TranslationsPF2e {
if (!game.ready) {
throw Error('PF2e System | TranslationsPF2e instantiated too early');
}
if (this._translations === undefined) {
this._translations = mergeObject(game.i18n._fallback, game.i18n.translations, {
enforceTypes: true,
});
}) as TranslationsPF2e;
}
return this._translations;
}
Expand Down
2 changes: 1 addition & 1 deletion src/module/system/world-clock/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DateTime } from 'luxon';
import { animateDarkness } from './animate-darkness';
import { LocalizePF2e } from '../localization';
import { LocalizePF2e } from '../localize';

interface WorldClockData {
date: string;
Expand Down
24 changes: 12 additions & 12 deletions src/scripts/hooks/ready.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { activateSocketListener } from '../socket';
import { activateSocketListener } from '@scripts/socket';
import { PlayerConfigPF2e } from '../../module/user/player-config';
import { WorldClock } from '../../module/system/world-clock';
import { updateMinionActors } from '../actor/update-minions';
import { MigrationRunner } from '../..//module/migration-runner';
import { updateMinionActors } from '@scripts/actor/update-minions';
import { MigrationRunner } from '../../module/migration-runner';
import { Migrations } from '../../module/migrations';
import { EffectPanel } from '../../module/system/effect-panel';
import { calculateXP } from '../macros/xp';
import { launchTravelSheet } from '../../module/gm/travel/travel-speed-sheet';
import { rollActionMacro, rollItemMacro } from '../init';
import { raiseAShield } from '../macros/raise-a-shield';
import { earnIncome } from '../macros/earn-income';
import { PF2Actions } from '../../module/system/actions/actions';
import { calculateXP } from '@scripts/macros/xp';
import { launchTravelSheet } from '@scripts/macros/travel/travel-speed-sheet';
import { rollActionMacro, rollItemMacro } from '@scripts/init';
import { raiseAShield } from '@scripts/macros/raise-a-shield';
import { earnIncome } from '@scripts/macros/earn-income';
import { PF2Actions } from '@system/actions/actions';
import { PF2eConditionManager } from '../../module/conditions';
import { PF2eStatusEffects } from '../actor/status-effects';
import { PF2eStatusEffects } from '@scripts/actor/status-effects';
import { WorldClock } from '@system/world-clock';
import { EffectPanel } from '@system/effect-panel';

export function listen(): void {
Hooks.once('ready', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/macros/raise-a-shield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PF2ECharacter } from '@actor/character';
import { PF2ENPC } from '@actor/npc';
import { PF2EEffect } from '@item/effect';
import { ActionDefaultOptions } from '../..//module/system/actions/actions';
import { LocalizePF2e } from '../../module/system/localization';
import { LocalizePF2e } from '../../module/system/localize';

/** Effect: Raise a Shield */
const ITEM_UUID = 'Compendium.pf2e.equipment-effects.2YgXoHvJfrDHucMr';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
TravelDuration,
Trip,
} from './travel-speed';
import { Fraction, zip } from '../../utils';
import { PF2EActor } from 'src/module/actor/actor';
import { Fraction, zip } from '@utils';
import { PF2EActor } from '@actor/actor';

type DetectionModeData = 'none' | 'everything' | 'before';
type SpeedUnitData = 'feet' | 'miles';
Expand Down Expand Up @@ -296,5 +296,5 @@ function toArray<T>(data: Record<number, T>): T[] {
}

export function launchTravelSheet(actors: PF2EActor[]): void {
new TravelSpeedSheet(null, { actors }).render(true);
new TravelSpeedSheet({}, { actors }).render(true);
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { sum, Fraction } from '@utils';

/**
* Implementation of travel speed https://2e.aonprd.com/Rules.aspx?ID=470
*/
import { Fraction, sum } from '../../utils';

export interface ExplorationOptions {
practicedDefender: boolean;
swiftSneak: boolean;
Expand Down
2 changes: 1 addition & 1 deletion tests/module/gm/travel/travel-speed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Terrain,
TerrainSlowdown,
Trip,
} from '../../../../src/module/gm/travel/travel-speed';
} from '@scripts/macros/travel/travel-speed';

const terrainModifiers: TerrainSlowdown = {
normal: { numerator: 1, denominator: 1 },
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"@actor/*": ["src/module/actor/*"],
"@item/*": ["src/module/item/*"],
"@scripts/*": ["src/scripts/*"],
"@system/*": ["src/module/system/*"]
"@system/*": ["src/module/system/*"],
"@utils": ["src/module/utils"]
},
"types": [
"jquery",
Expand Down
Loading

0 comments on commit 1c742ff

Please sign in to comment.