From f3adef6e800f3b1bed0f7c918dea845c82e7bf86 Mon Sep 17 00:00:00 2001 From: Luke Abby Date: Fri, 10 Nov 2023 14:44:53 -0800 Subject: [PATCH] Switch to Vitest --- .eslintrc.js | 2 +- package-lock.json | 1618 +++++++++-------- package.json | 6 +- src/foundry/client/apps/hud/chatbubble.d.ts | 184 +- test-d/foundry/client/apps/app.test-d.ts | 21 - .../foundry/client/apps/forms/actor.test-d.ts | 6 - .../apps/forms/combatant-config.test-d.ts | 14 - .../client/apps/forms/effect-config.test-d.ts | 12 - .../foundry/client/apps/forms/item.test-d.ts | 5 - .../client/apps/forms/journal-sheet.test-d.ts | 5 - .../client/apps/forms/macro-config.test-d.ts | 12 - .../client/apps/forms/user-config.test-d.ts | 9 - .../client/apps/hud/chatbubble.test-d.ts | 10 - .../client/apps/hud/container.test-d.ts | 9 - .../client/apps/hud/controls.test-d.ts | 55 - .../foundry/client/apps/hud/hotbar.test-d.ts | 14 - test-d/foundry/client/apps/hud/hud.test-d.ts | 14 - test-d/foundry/client/apps/hud/menu.test-d.ts | 13 - test-d/foundry/client/apps/i18n.test-d.ts | 18 - .../apps/placeables/drawing-hud.test-d.ts | 10 - .../apps/placeables/sound-config.test-d.ts | 9 - .../apps/placeables/tile-config.test-d.ts | 6 - .../client/apps/placeables/tile-hud.test-d.ts | 10 - .../apps/placeables/token-hud.test-d.ts | 11 - .../apps/sidebar/apps/chat-popout.test-d.ts | 6 - .../sidebar/tabs/combat-tracker.test-d.ts | 18 - .../apps/sidebar/tabs/settings.test-d.ts | 7 - test-d/foundry/client/audio/audio.test-d.ts | 65 - .../foundry/client/audio/container.test-d.ts | 20 - test-d/foundry/client/audio/sound.test-d.ts | 40 - test-d/foundry/client/core/hooks.test-d.ts | 25 - test-d/foundry/client/core/settings.test-d.ts | 80 - test-d/foundry/client/core/time.test-d.ts | 17 - test-d/foundry/client/core/utils.test-d.ts | 5 - .../data/abstract/canvas-document.test-d.ts | 24 - .../data/abstract/client-document.test-d.ts | 23 - .../client/data/collections/actors.test-d.ts | 7 - .../client/data/collections/combats.test-d.ts | 6 - .../data/collections/compendium.test-d.ts | 42 - .../client/data/collections/fog.test-d.ts | 6 - .../client/data/collections/folder.test-d.ts | 6 - .../client/data/collections/items.test-d.ts | 6 - .../client/data/collections/journal.test-d.ts | 6 - .../client/data/collections/macros.test-d.ts | 6 - .../data/collections/messages.test-d.ts | 6 - .../data/collections/playlists.test-d.ts | 7 - .../client/data/collections/scenes.test-d.ts | 8 - .../data/collections/settings.test-d.ts | 7 - .../client/data/collections/tables.test-d.ts | 7 - .../client/data/collections/users.test-d.ts | 6 - .../data/documents/active-effect.test-d.ts | 19 - .../client/data/documents/actor.test-d.ts | 33 - .../client/data/documents/card.test-d.ts | 83 - .../client/data/documents/cards.test-d.ts | 103 -- .../data/documents/chat-message.test-d.ts | 82 - .../client/data/documents/combatant.test-d.ts | 20 - .../client/data/documents/drawing.test-d.ts | 5 - .../data/documents/fog-exploration.test-d.ts | 19 - .../client/data/documents/folder.test-d.ts | 3 - .../client/data/documents/macro.test-d.ts | 30 - .../documents/measured-template.test-d.ts | 10 - .../client/data/documents/note.test-d.ts | 6 - .../client/data/documents/scene.test-d.ts | 24 - .../client/data/documents/setting.test-d.ts | 11 - .../client/data/documents/table.test-d.ts | 14 - .../client/data/documents/tile.test-d.ts | 4 - .../client/data/documents/token.test-d.ts | 45 - .../client/data/documents/user.test-d.ts | 31 - .../client/data/documents/wall.test-d.ts | 9 - test-d/foundry/client/dice/roll.test-d.ts | 82 - test-d/foundry/client/dice/term.test-d.ts | 23 - test-d/foundry/client/game.test-d.ts | 63 - test-d/foundry/client/head.test-d.ts | 4 - test-d/foundry/client/pixi/board.test-d.ts | 30 - .../containers/cached-container.test-d.ts | 16 - .../pixi/core/interaction/targets.test-d.ts | 11 - .../foundry/client/pixi/core/loader.test-d.ts | 9 - .../shapes/normalized-rectangle.test-d.ts | 7 - .../pixi/layers/controls/cursor.test-d.ts | 9 - .../pixi/layers/controls/door.test-d.ts | 14 - .../pixi/layers/controls/ruler.test-d.ts | 27 - .../client/pixi/layers/drawings.test-d.ts | 17 - .../client/pixi/layers/effects.test-d.ts | 15 - .../foundry/client/pixi/layers/grid.test-d.ts | 50 - .../pixi/layers/grid/highlight.test-d.ts | 11 - .../client/pixi/layers/lighting.test-d.ts | 14 - .../foundry/client/pixi/layers/map.test-d.ts | 41 - .../client/pixi/layers/notes.test-d.ts | 9 - .../client/pixi/layers/sounds.test-d.ts | 9 - .../client/pixi/layers/templates.test-d.ts | 15 - .../client/pixi/layers/tokens.test-d.ts | 9 - .../client/pixi/layers/walls.test-d.ts | 26 - .../pixi/perception/clockwise-sweep.test-d.ts | 36 - .../foundry/client/pixi/placeables.test-d.ts | 86 - .../client/pixi/placeables/drawing.test-d.ts | 19 - .../client/pixi/placeables/light.test-d.ts | 19 - .../client/pixi/placeables/note.test-d.ts | 11 - .../client/pixi/placeables/sound.test-d.ts | 21 - .../client/pixi/placeables/template.test-d.ts | 11 - .../client/pixi/placeables/tile.test-d.ts | 36 - .../client/pixi/placeables/token.test-d.ts | 17 - .../client/pixi/placeables/wall.test-d.ts | 21 - .../client/pixi/webgl/filters.test-d.ts | 7 - test-d/foundry/client/ui/drag.test-d.ts | 19 - test-d/foundry/client/ui/filter.test-d.ts | 30 - .../foundry/client/ui/notifications.test-d.ts | 37 - .../foundry/client/ui/prosemirror.test-d.ts | 13 - test-d/foundry/client/ui/tabs.test-d.ts | 23 - .../common/abstract/data.mjs.test-d.ts | 16 - .../common/abstract/document.mjs.test-d.ts | 117 -- .../common/data/data.mjs/actorData.test-d.ts | 101 - .../common/data/data.mjs/cardsData.test-d.ts | 76 - .../common/data/data.mjs/combatData.test-d.ts | 5 - .../data/data.mjs/combatantData.test-d.ts | 5 - .../common/data/data.mjs/folderData.test-d.ts | 8 - .../common/data/data.mjs/itemData.test-d.ts | 79 - .../data/data.mjs/journalEntryData.test-d.ts | 5 - .../common/data/data.mjs/macroData.test-d.ts | 5 - .../data.mjs/prototypeTokenData.test-d.ts | 7 - .../data/data.mjs/settingData.test-d.ts | 10 - .../common/data/data.mjs/userData.test-d.ts | 9 - .../common/data/data.mjs/wallData.test-d.ts | 91 - .../documents.mjs/baseActiveEffect.test-d.ts | 12 - .../common/documents.mjs/baseActor.test-d.ts | 116 -- .../documents.mjs/baseChatMessage.test-d.ts | 11 - .../common/documents.mjs/baseCombat.test-d.ts | 13 - .../documents.mjs/baseCombatant.test-d.ts | 16 - .../documents.mjs/baseDrawing.test-d.ts | 11 - .../baseFogExploration.test-d.ts | 11 - .../common/documents.mjs/baseFolder.test-d.ts | 16 - .../common/documents.mjs/baseItem.test-d.ts | 104 -- .../documents.mjs/baseJournalEntry.test-d.ts | 16 - .../baseMeasuredTemplate.test-d.ts | 6 - .../common/documents.mjs/baseScene.test-d.ts | 79 - .../documents.mjs/baseSetting.test-d.ts | 16 - .../common/documents.mjs/baseUser.test-d.ts | 92 - .../common/documents.mjs/baseWall.test-d.ts | 9 - .../common/primitives/array.mjs.test-d.ts | 9 - .../common/primitives/set.mjs.test-d.ts | 9 - .../common/primitives/string.mjs.test-d.ts | 12 - .../common/utils/collection.mjs.test-d.ts | 23 - .../common/utils/helpers.mjs.test-d.ts | 407 ----- .../foundry/common/utils/http.mjs.test-d.ts | 4 - .../common/utils/semaphore.mjs.test-d.ts | 10 - .../foundry/prosemirror/prosemirror.test-d.ts | 7 - test-d/tsconfig.json | 7 - test-d/types/utils.test-d.ts | 100 - tests/.gitignore | 1 + .../custom/custom-error-hooks.d.ts | 0 {test-d => tests}/custom/custom-hooks.d.ts | 0 tests/foundry/client/apps/app.test-d.ts | 21 + .../client/apps/av/av-config.test-d.ts | 0 .../foundry/client/apps/form.test-d.ts | 16 +- .../foundry/client/apps/forms/actor.test-d.ts | 6 + .../apps/forms/combatant-config.test-d.ts | 15 + .../client/apps/forms/effect-config.test-d.ts | 13 + .../foundry/client/apps/forms/item.test-d.ts | 5 + .../client/apps/forms/journal-sheet.test-d.ts | 5 + .../client/apps/forms/macro-config.test-d.ts | 13 + .../client/apps/forms/user-config.test-d.ts | 10 + .../client/apps/hud/chatbubble.test-d.ts | 10 + .../client/apps/hud/container.test-d.ts | 9 + .../client/apps/hud/controls.test-d.ts | 59 + .../foundry/client/apps/hud/hotbar.test-d.ts | 14 + tests/foundry/client/apps/hud/hud.test-d.ts | 14 + tests/foundry/client/apps/hud/menu.test-d.ts | 13 + tests/foundry/client/apps/i18n.test-d.ts | 18 + .../apps/placeables/drawing-hud.test-d.ts | 10 + .../apps/placeables/sound-config.test-d.ts | 9 + .../apps/placeables/tile-config.test-d.ts | 6 + .../client/apps/placeables/tile-hud.test-d.ts | 10 + .../apps/placeables/token-hud.test-d.ts | 11 + .../apps/sidebar/apps/chat-popout.test-d.ts | 6 + .../sidebar/tabs/combat-tracker.test-d.ts | 18 + .../apps/sidebar/tabs/settings.test-d.ts | 7 + tests/foundry/client/audio/audio.test-d.ts | 65 + .../foundry/client/audio/container.test-d.ts | 22 + tests/foundry/client/audio/sound.test-d.ts | 40 + .../foundry/client/av/master.test-d.ts | 6 +- .../foundry/client/av/settings.test-d.ts | 6 +- tests/foundry/client/core/hooks.test-d.ts | 25 + tests/foundry/client/core/settings.test-d.ts | 79 + tests/foundry/client/core/time.test-d.ts | 17 + tests/foundry/client/core/utils.test-d.ts | 5 + .../data/abstract/canvas-document.test-d.ts | 24 + .../data/abstract/client-document.test-d.ts | 23 + .../client/data/collections/actors.test-d.ts | 7 + .../client/data/collections/combats.test-d.ts | 6 + .../data/collections/compendium.test-d.ts | 45 + .../client/data/collections/fog.test-d.ts | 6 + .../client/data/collections/folder.test-d.ts | 6 + .../client/data/collections/items.test-d.ts | 6 + .../client/data/collections/journal.test-d.ts | 6 + .../client/data/collections/macros.test-d.ts | 6 + .../data/collections/messages.test-d.ts | 6 + .../data/collections/playlists.test-d.ts | 7 + .../client/data/collections/scenes.test-d.ts | 8 + .../data/collections/settings.test-d.ts | 7 + .../client/data/collections/tables.test-d.ts | 7 + .../client/data/collections/users.test-d.ts | 6 + .../data/documents/active-effect.test-d.ts | 26 + .../client/data/documents/actor.test-d.ts | 33 + .../client/data/documents/card.test-d.ts | 99 + .../client/data/documents/cards.test-d.ts | 124 ++ .../data/documents/chat-message.test-d.ts | 86 + .../client/data/documents/combatant.test-d.ts | 22 + .../client/data/documents/drawing.test-d.ts | 5 + .../data/documents/fog-exploration.test-d.ts | 21 + .../client/data/documents/folder.test-d.ts | 3 + .../client/data/documents/item.test-d.ts | 14 +- .../client/data/documents/macro.test-d.ts | 30 + .../documents/measured-template.test-d.ts | 10 + .../client/data/documents/note.test-d.ts | 6 + .../client/data/documents/scene.test-d.ts | 29 + .../client/data/documents/setting.test-d.ts | 13 + .../client/data/documents/table.test-d.ts | 15 + .../client/data/documents/tile.test-d.ts | 4 + .../client/data/documents/token.test-d.ts | 45 + .../client/data/documents/user.test-d.ts | 33 + .../client/data/documents/wall.test-d.ts | 10 + .../foundry/client/dice/dice/coin.test-d.ts | 0 .../foundry/client/dice/dice/die.test-d.ts | 0 .../foundry/client/dice/dice/fate.test-d.ts | 0 tests/foundry/client/dice/roll.test-d.ts | 90 + tests/foundry/client/dice/term.test-d.ts | 25 + tests/foundry/client/game.test-d.ts | 64 + tests/foundry/client/head.test-d.ts | 4 + tests/foundry/client/pixi/board.test-d.ts | 32 + .../containers/cached-container.test-d.ts | 16 + .../pixi/core/interaction/targets.test-d.ts | 11 + .../foundry/client/pixi/core/loader.test-d.ts | 11 + .../shapes/normalized-rectangle.test-d.ts | 7 + .../pixi/layers/controls/cursor.test-d.ts | 9 + .../pixi/layers/controls/door.test-d.ts | 15 + .../pixi/layers/controls/ruler.test-d.ts | 27 + .../client/pixi/layers/drawings.test-d.ts | 17 + .../client/pixi/layers/effects.test-d.ts | 15 + .../foundry/client/pixi/layers/grid.test-d.ts | 56 + .../pixi/layers/grid/highlight.test-d.ts | 11 + .../client/pixi/layers/lighting.test-d.ts | 14 + .../foundry/client/pixi/layers/map.test-d.ts | 47 + .../client/pixi/layers/notes.test-d.ts | 9 + .../client/pixi/layers/sounds.test-d.ts | 9 + .../client/pixi/layers/templates.test-d.ts | 15 + .../client/pixi/layers/tokens.test-d.ts | 9 + .../client/pixi/layers/walls.test-d.ts | 36 + .../pixi/perception/clockwise-sweep.test-d.ts | 38 + .../perception/perception-manager.test-d.ts | 34 +- .../foundry/client/pixi/placeable.test-d.ts | 12 +- .../foundry/client/pixi/placeables.test-d.ts | 107 ++ .../client/pixi/placeables/drawing.test-d.ts | 19 + .../client/pixi/placeables/light.test-d.ts | 19 + .../client/pixi/placeables/note.test-d.ts | 11 + .../client/pixi/placeables/sound.test-d.ts | 22 + .../client/pixi/placeables/template.test-d.ts | 11 + .../client/pixi/placeables/tile.test-d.ts | 36 + .../client/pixi/placeables/token.test-d.ts | 19 + .../client/pixi/placeables/wall.test-d.ts | 25 + .../foundry/client/pixi/webgl/base.test-d.ts | 9 +- .../client/pixi/webgl/filters.test-d.ts | 7 + .../foundry/client/ui/context.test-d.ts | 8 +- .../foundry/client/ui/dialog.test-d.ts | 337 ++-- tests/foundry/client/ui/drag.test-d.ts | 19 + tests/foundry/client/ui/filter.test-d.ts | 37 + .../foundry/client/ui/notifications.test-d.ts | 40 + tests/foundry/client/ui/prosemirror.test-d.ts | 18 + tests/foundry/client/ui/tabs.test-d.ts | 29 + .../common/abstract/data.mjs.test-d.ts | 19 + .../common/abstract/document.mjs.test-d.ts | 133 ++ .../common/data/data.mjs/actorData.test-d.ts | 112 ++ .../data/data.mjs/ambientSoundData.test-d.ts | 18 +- .../common/data/data.mjs/cardData.test-d.ts | 39 +- .../common/data/data.mjs/cardsData.test-d.ts | 85 + .../data/data.mjs/chatMessageData.test-d.ts | 38 +- .../common/data/data.mjs/combatData.test-d.ts | 5 + .../data/data.mjs/combatantData.test-d.ts | 7 + .../data/data.mjs/drawingData.test-d.ts | 18 +- .../data.mjs/fogExplorationData.test-d.ts | 19 +- .../common/data/data.mjs/folderData.test-d.ts | 14 + .../common/data/data.mjs/itemData.test-d.ts | 87 + .../data/data.mjs/journalEntryData.test-d.ts | 9 + .../common/data/data.mjs/macroData.test-d.ts | 9 + .../data.mjs/measuredTemplateData.test-d.ts | 32 +- .../common/data/data.mjs/noteData.test-d.ts | 21 +- .../data.mjs/prototypeTokenData.test-d.ts | 7 + .../common/data/data.mjs/sceneData.test-d.ts | 20 +- .../data/data.mjs/settingData.test-d.ts | 22 + .../common/data/data.mjs/tileData.test-d.ts | 35 +- .../common/data/data.mjs/userData.test-d.ts | 17 + .../common/data/data.mjs/wallData.test-d.ts | 95 + .../documents.mjs/baseActiveEffect.test-d.ts | 16 + .../common/documents.mjs/baseActor.test-d.ts | 120 ++ .../common/documents.mjs/baseCard.test-d.ts | 38 +- .../common/documents.mjs/baseCards.test-d.ts | 40 +- .../documents.mjs/baseChatMessage.test-d.ts | 15 + .../common/documents.mjs/baseCombat.test-d.ts | 13 + .../documents.mjs/baseCombatant.test-d.ts | 16 + .../documents.mjs/baseDrawing.test-d.ts | 15 + .../baseFogExploration.test-d.ts | 15 + .../common/documents.mjs/baseFolder.test-d.ts | 16 + .../common/documents.mjs/baseItem.test-d.ts | 113 ++ .../documents.mjs/baseJournalEntry.test-d.ts | 18 + .../baseMeasuredTemplate.test-d.ts | 6 + .../common/documents.mjs/baseScene.test-d.ts | 86 + .../documents.mjs/baseSetting.test-d.ts | 16 + .../common/documents.mjs/baseUser.test-d.ts | 111 ++ .../common/documents.mjs/baseWall.test-d.ts | 12 + .../common/primitives/array.mjs.test-d.ts | 9 + .../common/primitives/set.mjs.test-d.ts | 13 + .../common/primitives/string.mjs.test-d.ts | 12 + .../common/utils/collection.mjs.test-d.ts | 23 + .../common/utils/helpers.mjs.test-d.ts | 429 +++++ tests/foundry/common/utils/http.mjs.test-d.ts | 4 + .../common/utils/semaphore.mjs.test-d.ts | 13 + .../foundry/prosemirror/prosemirror.test-d.ts | 7 + tests/tsconfig.json | 7 + tests/types/utils.test-d.ts | 100 + tsconfig.eslint.json | 4 + vitest.config.js | 11 + 319 files changed, 5590 insertions(+), 5010 deletions(-) delete mode 100644 test-d/foundry/client/apps/app.test-d.ts delete mode 100644 test-d/foundry/client/apps/forms/actor.test-d.ts delete mode 100644 test-d/foundry/client/apps/forms/combatant-config.test-d.ts delete mode 100644 test-d/foundry/client/apps/forms/effect-config.test-d.ts delete mode 100644 test-d/foundry/client/apps/forms/item.test-d.ts delete mode 100644 test-d/foundry/client/apps/forms/journal-sheet.test-d.ts delete mode 100644 test-d/foundry/client/apps/forms/macro-config.test-d.ts delete mode 100644 test-d/foundry/client/apps/forms/user-config.test-d.ts delete mode 100644 test-d/foundry/client/apps/hud/chatbubble.test-d.ts delete mode 100644 test-d/foundry/client/apps/hud/container.test-d.ts delete mode 100644 test-d/foundry/client/apps/hud/controls.test-d.ts delete mode 100644 test-d/foundry/client/apps/hud/hotbar.test-d.ts delete mode 100644 test-d/foundry/client/apps/hud/hud.test-d.ts delete mode 100644 test-d/foundry/client/apps/hud/menu.test-d.ts delete mode 100644 test-d/foundry/client/apps/i18n.test-d.ts delete mode 100644 test-d/foundry/client/apps/placeables/drawing-hud.test-d.ts delete mode 100644 test-d/foundry/client/apps/placeables/sound-config.test-d.ts delete mode 100644 test-d/foundry/client/apps/placeables/tile-config.test-d.ts delete mode 100644 test-d/foundry/client/apps/placeables/tile-hud.test-d.ts delete mode 100644 test-d/foundry/client/apps/placeables/token-hud.test-d.ts delete mode 100644 test-d/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts delete mode 100644 test-d/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts delete mode 100644 test-d/foundry/client/apps/sidebar/tabs/settings.test-d.ts delete mode 100644 test-d/foundry/client/audio/audio.test-d.ts delete mode 100644 test-d/foundry/client/audio/container.test-d.ts delete mode 100644 test-d/foundry/client/audio/sound.test-d.ts delete mode 100644 test-d/foundry/client/core/hooks.test-d.ts delete mode 100644 test-d/foundry/client/core/settings.test-d.ts delete mode 100644 test-d/foundry/client/core/time.test-d.ts delete mode 100644 test-d/foundry/client/core/utils.test-d.ts delete mode 100644 test-d/foundry/client/data/abstract/canvas-document.test-d.ts delete mode 100644 test-d/foundry/client/data/abstract/client-document.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/actors.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/combats.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/compendium.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/fog.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/folder.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/items.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/journal.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/macros.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/messages.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/playlists.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/scenes.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/settings.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/tables.test-d.ts delete mode 100644 test-d/foundry/client/data/collections/users.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/active-effect.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/actor.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/card.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/cards.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/chat-message.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/combatant.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/drawing.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/fog-exploration.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/folder.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/macro.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/measured-template.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/note.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/scene.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/setting.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/table.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/tile.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/token.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/user.test-d.ts delete mode 100644 test-d/foundry/client/data/documents/wall.test-d.ts delete mode 100644 test-d/foundry/client/dice/roll.test-d.ts delete mode 100644 test-d/foundry/client/dice/term.test-d.ts delete mode 100644 test-d/foundry/client/game.test-d.ts delete mode 100644 test-d/foundry/client/head.test-d.ts delete mode 100644 test-d/foundry/client/pixi/board.test-d.ts delete mode 100644 test-d/foundry/client/pixi/core/containers/cached-container.test-d.ts delete mode 100644 test-d/foundry/client/pixi/core/interaction/targets.test-d.ts delete mode 100644 test-d/foundry/client/pixi/core/loader.test-d.ts delete mode 100644 test-d/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/controls/cursor.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/controls/door.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/controls/ruler.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/drawings.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/effects.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/grid.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/grid/highlight.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/lighting.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/map.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/notes.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/sounds.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/templates.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/tokens.test-d.ts delete mode 100644 test-d/foundry/client/pixi/layers/walls.test-d.ts delete mode 100644 test-d/foundry/client/pixi/perception/clockwise-sweep.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/drawing.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/light.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/note.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/sound.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/template.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/tile.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/token.test-d.ts delete mode 100644 test-d/foundry/client/pixi/placeables/wall.test-d.ts delete mode 100644 test-d/foundry/client/pixi/webgl/filters.test-d.ts delete mode 100644 test-d/foundry/client/ui/drag.test-d.ts delete mode 100644 test-d/foundry/client/ui/filter.test-d.ts delete mode 100644 test-d/foundry/client/ui/notifications.test-d.ts delete mode 100644 test-d/foundry/client/ui/prosemirror.test-d.ts delete mode 100644 test-d/foundry/client/ui/tabs.test-d.ts delete mode 100644 test-d/foundry/common/abstract/data.mjs.test-d.ts delete mode 100644 test-d/foundry/common/abstract/document.mjs.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/actorData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/cardsData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/combatData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/combatantData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/folderData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/itemData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/journalEntryData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/macroData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/settingData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/userData.test-d.ts delete mode 100644 test-d/foundry/common/data/data.mjs/wallData.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseActiveEffect.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseActor.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseChatMessage.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseCombat.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseCombatant.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseDrawing.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseFogExploration.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseFolder.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseItem.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseJournalEntry.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseScene.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseSetting.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseUser.test-d.ts delete mode 100644 test-d/foundry/common/documents.mjs/baseWall.test-d.ts delete mode 100644 test-d/foundry/common/primitives/array.mjs.test-d.ts delete mode 100644 test-d/foundry/common/primitives/set.mjs.test-d.ts delete mode 100644 test-d/foundry/common/primitives/string.mjs.test-d.ts delete mode 100644 test-d/foundry/common/utils/collection.mjs.test-d.ts delete mode 100644 test-d/foundry/common/utils/helpers.mjs.test-d.ts delete mode 100644 test-d/foundry/common/utils/http.mjs.test-d.ts delete mode 100644 test-d/foundry/common/utils/semaphore.mjs.test-d.ts delete mode 100644 test-d/foundry/prosemirror/prosemirror.test-d.ts delete mode 100644 test-d/tsconfig.json delete mode 100644 test-d/types/utils.test-d.ts create mode 100644 tests/.gitignore rename {test-d => tests}/custom/custom-error-hooks.d.ts (100%) rename {test-d => tests}/custom/custom-hooks.d.ts (100%) create mode 100644 tests/foundry/client/apps/app.test-d.ts rename {test-d => tests}/foundry/client/apps/av/av-config.test-d.ts (100%) rename {test-d => tests}/foundry/client/apps/form.test-d.ts (50%) create mode 100644 tests/foundry/client/apps/forms/actor.test-d.ts create mode 100644 tests/foundry/client/apps/forms/combatant-config.test-d.ts create mode 100644 tests/foundry/client/apps/forms/effect-config.test-d.ts create mode 100644 tests/foundry/client/apps/forms/item.test-d.ts create mode 100644 tests/foundry/client/apps/forms/journal-sheet.test-d.ts create mode 100644 tests/foundry/client/apps/forms/macro-config.test-d.ts create mode 100644 tests/foundry/client/apps/forms/user-config.test-d.ts create mode 100644 tests/foundry/client/apps/hud/chatbubble.test-d.ts create mode 100644 tests/foundry/client/apps/hud/container.test-d.ts create mode 100644 tests/foundry/client/apps/hud/controls.test-d.ts create mode 100644 tests/foundry/client/apps/hud/hotbar.test-d.ts create mode 100644 tests/foundry/client/apps/hud/hud.test-d.ts create mode 100644 tests/foundry/client/apps/hud/menu.test-d.ts create mode 100644 tests/foundry/client/apps/i18n.test-d.ts create mode 100644 tests/foundry/client/apps/placeables/drawing-hud.test-d.ts create mode 100644 tests/foundry/client/apps/placeables/sound-config.test-d.ts create mode 100644 tests/foundry/client/apps/placeables/tile-config.test-d.ts create mode 100644 tests/foundry/client/apps/placeables/tile-hud.test-d.ts create mode 100644 tests/foundry/client/apps/placeables/token-hud.test-d.ts create mode 100644 tests/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts create mode 100644 tests/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts create mode 100644 tests/foundry/client/apps/sidebar/tabs/settings.test-d.ts create mode 100644 tests/foundry/client/audio/audio.test-d.ts create mode 100644 tests/foundry/client/audio/container.test-d.ts create mode 100644 tests/foundry/client/audio/sound.test-d.ts rename {test-d => tests}/foundry/client/av/master.test-d.ts (79%) rename {test-d => tests}/foundry/client/av/settings.test-d.ts (64%) create mode 100644 tests/foundry/client/core/hooks.test-d.ts create mode 100644 tests/foundry/client/core/settings.test-d.ts create mode 100644 tests/foundry/client/core/time.test-d.ts create mode 100644 tests/foundry/client/core/utils.test-d.ts create mode 100644 tests/foundry/client/data/abstract/canvas-document.test-d.ts create mode 100644 tests/foundry/client/data/abstract/client-document.test-d.ts create mode 100644 tests/foundry/client/data/collections/actors.test-d.ts create mode 100644 tests/foundry/client/data/collections/combats.test-d.ts create mode 100644 tests/foundry/client/data/collections/compendium.test-d.ts create mode 100644 tests/foundry/client/data/collections/fog.test-d.ts create mode 100644 tests/foundry/client/data/collections/folder.test-d.ts create mode 100644 tests/foundry/client/data/collections/items.test-d.ts create mode 100644 tests/foundry/client/data/collections/journal.test-d.ts create mode 100644 tests/foundry/client/data/collections/macros.test-d.ts create mode 100644 tests/foundry/client/data/collections/messages.test-d.ts create mode 100644 tests/foundry/client/data/collections/playlists.test-d.ts create mode 100644 tests/foundry/client/data/collections/scenes.test-d.ts create mode 100644 tests/foundry/client/data/collections/settings.test-d.ts create mode 100644 tests/foundry/client/data/collections/tables.test-d.ts create mode 100644 tests/foundry/client/data/collections/users.test-d.ts create mode 100644 tests/foundry/client/data/documents/active-effect.test-d.ts create mode 100644 tests/foundry/client/data/documents/actor.test-d.ts create mode 100644 tests/foundry/client/data/documents/card.test-d.ts create mode 100644 tests/foundry/client/data/documents/cards.test-d.ts create mode 100644 tests/foundry/client/data/documents/chat-message.test-d.ts create mode 100644 tests/foundry/client/data/documents/combatant.test-d.ts create mode 100644 tests/foundry/client/data/documents/drawing.test-d.ts create mode 100644 tests/foundry/client/data/documents/fog-exploration.test-d.ts create mode 100644 tests/foundry/client/data/documents/folder.test-d.ts rename {test-d => tests}/foundry/client/data/documents/item.test-d.ts (71%) create mode 100644 tests/foundry/client/data/documents/macro.test-d.ts create mode 100644 tests/foundry/client/data/documents/measured-template.test-d.ts create mode 100644 tests/foundry/client/data/documents/note.test-d.ts create mode 100644 tests/foundry/client/data/documents/scene.test-d.ts create mode 100644 tests/foundry/client/data/documents/setting.test-d.ts create mode 100644 tests/foundry/client/data/documents/table.test-d.ts create mode 100644 tests/foundry/client/data/documents/tile.test-d.ts create mode 100644 tests/foundry/client/data/documents/token.test-d.ts create mode 100644 tests/foundry/client/data/documents/user.test-d.ts create mode 100644 tests/foundry/client/data/documents/wall.test-d.ts rename {test-d => tests}/foundry/client/dice/dice/coin.test-d.ts (100%) rename {test-d => tests}/foundry/client/dice/dice/die.test-d.ts (100%) rename {test-d => tests}/foundry/client/dice/dice/fate.test-d.ts (100%) create mode 100644 tests/foundry/client/dice/roll.test-d.ts create mode 100644 tests/foundry/client/dice/term.test-d.ts create mode 100644 tests/foundry/client/game.test-d.ts create mode 100644 tests/foundry/client/head.test-d.ts create mode 100644 tests/foundry/client/pixi/board.test-d.ts create mode 100644 tests/foundry/client/pixi/core/containers/cached-container.test-d.ts create mode 100644 tests/foundry/client/pixi/core/interaction/targets.test-d.ts create mode 100644 tests/foundry/client/pixi/core/loader.test-d.ts create mode 100644 tests/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/controls/cursor.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/controls/door.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/controls/ruler.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/drawings.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/effects.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/grid.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/grid/highlight.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/lighting.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/map.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/notes.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/sounds.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/templates.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/tokens.test-d.ts create mode 100644 tests/foundry/client/pixi/layers/walls.test-d.ts create mode 100644 tests/foundry/client/pixi/perception/clockwise-sweep.test-d.ts rename {test-d => tests}/foundry/client/pixi/perception/perception-manager.test-d.ts (55%) rename {test-d => tests}/foundry/client/pixi/placeable.test-d.ts (80%) create mode 100644 tests/foundry/client/pixi/placeables.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/drawing.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/light.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/note.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/sound.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/template.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/tile.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/token.test-d.ts create mode 100644 tests/foundry/client/pixi/placeables/wall.test-d.ts rename {test-d => tests}/foundry/client/pixi/webgl/base.test-d.ts (60%) create mode 100644 tests/foundry/client/pixi/webgl/filters.test-d.ts rename {test-d => tests}/foundry/client/ui/context.test-d.ts (69%) rename {test-d => tests}/foundry/client/ui/dialog.test-d.ts (56%) create mode 100644 tests/foundry/client/ui/drag.test-d.ts create mode 100644 tests/foundry/client/ui/filter.test-d.ts create mode 100644 tests/foundry/client/ui/notifications.test-d.ts create mode 100644 tests/foundry/client/ui/prosemirror.test-d.ts create mode 100644 tests/foundry/client/ui/tabs.test-d.ts create mode 100644 tests/foundry/common/abstract/data.mjs.test-d.ts create mode 100644 tests/foundry/common/abstract/document.mjs.test-d.ts create mode 100644 tests/foundry/common/data/data.mjs/actorData.test-d.ts rename {test-d => tests}/foundry/common/data/data.mjs/ambientSoundData.test-d.ts (62%) rename {test-d => tests}/foundry/common/data/data.mjs/cardData.test-d.ts (53%) create mode 100644 tests/foundry/common/data/data.mjs/cardsData.test-d.ts rename {test-d => tests}/foundry/common/data/data.mjs/chatMessageData.test-d.ts (61%) create mode 100644 tests/foundry/common/data/data.mjs/combatData.test-d.ts create mode 100644 tests/foundry/common/data/data.mjs/combatantData.test-d.ts rename {test-d => tests}/foundry/common/data/data.mjs/drawingData.test-d.ts (80%) rename {test-d => tests}/foundry/common/data/data.mjs/fogExplorationData.test-d.ts (60%) create mode 100644 tests/foundry/common/data/data.mjs/folderData.test-d.ts create mode 100644 tests/foundry/common/data/data.mjs/itemData.test-d.ts create mode 100644 tests/foundry/common/data/data.mjs/journalEntryData.test-d.ts create mode 100644 tests/foundry/common/data/data.mjs/macroData.test-d.ts rename {test-d => tests}/foundry/common/data/data.mjs/measuredTemplateData.test-d.ts (53%) rename {test-d => tests}/foundry/common/data/data.mjs/noteData.test-d.ts (66%) create mode 100644 tests/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts rename {test-d => tests}/foundry/common/data/data.mjs/sceneData.test-d.ts (82%) create mode 100644 tests/foundry/common/data/data.mjs/settingData.test-d.ts rename {test-d => tests}/foundry/common/data/data.mjs/tileData.test-d.ts (67%) create mode 100644 tests/foundry/common/data/data.mjs/userData.test-d.ts create mode 100644 tests/foundry/common/data/data.mjs/wallData.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseActiveEffect.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseActor.test-d.ts rename {test-d => tests}/foundry/common/documents.mjs/baseCard.test-d.ts (58%) rename {test-d => tests}/foundry/common/documents.mjs/baseCards.test-d.ts (50%) create mode 100644 tests/foundry/common/documents.mjs/baseChatMessage.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseCombat.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseCombatant.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseDrawing.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseFogExploration.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseFolder.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseItem.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseJournalEntry.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseScene.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseSetting.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseUser.test-d.ts create mode 100644 tests/foundry/common/documents.mjs/baseWall.test-d.ts create mode 100644 tests/foundry/common/primitives/array.mjs.test-d.ts create mode 100644 tests/foundry/common/primitives/set.mjs.test-d.ts create mode 100644 tests/foundry/common/primitives/string.mjs.test-d.ts create mode 100644 tests/foundry/common/utils/collection.mjs.test-d.ts create mode 100644 tests/foundry/common/utils/helpers.mjs.test-d.ts create mode 100644 tests/foundry/common/utils/http.mjs.test-d.ts create mode 100644 tests/foundry/common/utils/semaphore.mjs.test-d.ts create mode 100644 tests/foundry/prosemirror/prosemirror.test-d.ts create mode 100644 tests/tsconfig.json create mode 100644 tests/types/utils.test-d.ts create mode 100644 tsconfig.eslint.json create mode 100644 vitest.config.js diff --git a/.eslintrc.js b/.eslintrc.js index 44bfed569..a36937ed6 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -5,7 +5,7 @@ module.exports = { extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"], parser: "@typescript-eslint/parser", parserOptions: { - project: "./test-d/tsconfig.json", + project: "./tsconfig.eslint.json", sourceType: "module", }, plugins: ["@typescript-eslint", "eslint-plugin-tsdoc"], diff --git a/package-lock.json b/package-lock.json index 0eab0ce24..048a8af28 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,8 +40,8 @@ "is-ci": "^3.0.1", "lint-staged": "^15.0.1", "prettier": "^3.0.3", - "tsd": "~0.29", - "typescript": "~5.2" + "typescript": "~5.2", + "vitest": "^0.34.6" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -52,165 +52,356 @@ "node": ">=0.10.0" } }, - "node_modules/@babel/code-frame": { - "version": "7.22.13", + "node_modules/@esbuild/android-arm": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.18.20.tgz", + "integrity": "sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==", + "cpu": [ + "arm" + ], "dev": true, - "license": "MIT", - "dependencies": { - "@babel/highlight": "^7.22.13", - "chalk": "^2.4.2" - }, + "optional": true, + "os": [ + "android" + ], "engines": { - "node": ">=6.9.0" + "node": ">=12" } }, - "node_modules/@babel/code-frame/node_modules/ansi-styles": { - "version": "3.2.1", + "node_modules/@esbuild/android-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.18.20.tgz", + "integrity": "sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT", - "dependencies": { - "color-convert": "^1.9.0" - }, + "optional": true, + "os": [ + "android" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/@babel/code-frame/node_modules/chalk": { - "version": "2.4.2", + "node_modules/@esbuild/android-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.18.20.tgz", + "integrity": "sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, + "optional": true, + "os": [ + "android" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/@babel/code-frame/node_modules/color-convert": { - "version": "1.9.3", + "node_modules/@esbuild/darwin-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz", + "integrity": "sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "1.1.3" + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" } }, - "node_modules/@babel/code-frame/node_modules/color-name": { - "version": "1.1.3", + "node_modules/@esbuild/darwin-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.18.20.tgz", + "integrity": "sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT" + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } }, - "node_modules/@babel/code-frame/node_modules/escape-string-regexp": { - "version": "1.0.5", + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.20.tgz", + "integrity": "sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], "engines": { - "node": ">=0.8.0" + "node": ">=12" } }, - "node_modules/@babel/code-frame/node_modules/has-flag": { - "version": "3.0.0", + "node_modules/@esbuild/freebsd-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.18.20.tgz", + "integrity": "sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/@babel/code-frame/node_modules/supports-color": { - "version": "5.5.0", + "node_modules/@esbuild/linux-arm": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.18.20.tgz", + "integrity": "sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==", + "cpu": [ + "arm" + ], "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^3.0.0" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.20", + "node_modules/@esbuild/linux-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.18.20.tgz", + "integrity": "sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==", + "cpu": [ + "arm64" + ], "dev": true, - "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=6.9.0" + "node": ">=12" } }, - "node_modules/@babel/highlight": { - "version": "7.22.20", + "node_modules/@esbuild/linux-ia32": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.18.20.tgz", + "integrity": "sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==", + "cpu": [ + "ia32" + ], "dev": true, - "license": "MIT", - "dependencies": { - "@babel/helper-validator-identifier": "^7.22.20", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=6.9.0" + "node": ">=12" } }, - "node_modules/@babel/highlight/node_modules/ansi-styles": { - "version": "3.2.1", + "node_modules/@esbuild/linux-loong64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.18.20.tgz", + "integrity": "sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==", + "cpu": [ + "loong64" + ], "dev": true, - "license": "MIT", - "dependencies": { - "color-convert": "^1.9.0" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/@babel/highlight/node_modules/chalk": { - "version": "2.4.2", + "node_modules/@esbuild/linux-mips64el": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.18.20.tgz", + "integrity": "sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==", + "cpu": [ + "mips64el" + ], "dev": true, - "license": "MIT", - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/@babel/highlight/node_modules/color-convert": { - "version": "1.9.3", + "node_modules/@esbuild/linux-ppc64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.18.20.tgz", + "integrity": "sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==", + "cpu": [ + "ppc64" + ], "dev": true, - "license": "MIT", - "dependencies": { - "color-name": "1.1.3" + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" } }, - "node_modules/@babel/highlight/node_modules/color-name": { - "version": "1.1.3", + "node_modules/@esbuild/linux-riscv64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.18.20.tgz", + "integrity": "sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==", + "cpu": [ + "riscv64" + ], "dev": true, - "license": "MIT" + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } }, - "node_modules/@babel/highlight/node_modules/escape-string-regexp": { - "version": "1.0.5", + "node_modules/@esbuild/linux-s390x": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.18.20.tgz", + "integrity": "sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==", + "cpu": [ + "s390x" + ], "dev": true, - "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=0.8.0" + "node": ">=12" } }, - "node_modules/@babel/highlight/node_modules/has-flag": { - "version": "3.0.0", + "node_modules/@esbuild/linux-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz", + "integrity": "sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT", + "optional": true, + "os": [ + "linux" + ], "engines": { - "node": ">=4" + "node": ">=12" } }, - "node_modules/@babel/highlight/node_modules/supports-color": { - "version": "5.5.0", + "node_modules/@esbuild/netbsd-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.18.20.tgz", + "integrity": "sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==", + "cpu": [ + "x64" + ], "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^3.0.0" - }, + "optional": true, + "os": [ + "netbsd" + ], "engines": { - "node": ">=4" + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.18.20.tgz", + "integrity": "sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.18.20.tgz", + "integrity": "sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.18.20.tgz", + "integrity": "sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.18.20.tgz", + "integrity": "sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz", + "integrity": "sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" } }, "node_modules/@eslint-community/eslint-utils": { @@ -301,8 +492,9 @@ }, "node_modules/@jest/schemas": { "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", "dev": true, - "license": "MIT", "dependencies": { "@sinclair/typebox": "^0.27.8" }, @@ -310,6 +502,12 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==", + "dev": true + }, "node_modules/@microsoft/tsdoc": { "version": "0.14.2", "dev": true, @@ -2101,19 +2299,27 @@ }, "node_modules/@sinclair/typebox": { "version": "0.27.8", - "dev": true, - "license": "MIT" + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", + "dev": true }, "node_modules/@socket.io/component-emitter": { "version": "3.1.0", "license": "MIT" }, - "node_modules/@tsd/typescript": { - "version": "5.2.2", + "node_modules/@types/chai": { + "version": "4.3.10", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.10.tgz", + "integrity": "sha512-of+ICnbqjmFCiixUnqRulbylyXQrPqIGf/B3Jax1wIF3DvSheysQxAWvqHhZiW3IQrycvokcLcFQlveGp+vyNg==", + "dev": true + }, + "node_modules/@types/chai-subset": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/@types/chai-subset/-/chai-subset-1.3.5.tgz", + "integrity": "sha512-c2mPnw+xHtXDoHmdtcCXGwyLMiauiAyxWMzhGpqHC4nqI/Y5G2XhTampslK2rb59kpcuHon03UH8W6iYUzw88A==", "dev": true, - "license": "MIT", - "engines": { - "node": ">=14.17" + "dependencies": { + "@types/chai": "*" } }, "node_modules/@types/earcut": { @@ -2136,7 +2342,9 @@ "node_modules/@types/estree": { "version": "1.0.2", "dev": true, - "license": "MIT" + "license": "MIT", + "optional": true, + "peer": true }, "node_modules/@types/jquery": { "version": "3.5.27", @@ -2151,20 +2359,10 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/minimist": { - "version": "1.2.3", - "dev": true, - "license": "MIT" - }, "node_modules/@types/node": { "version": "20.8.3", "license": "MIT" }, - "node_modules/@types/normalize-package-data": { - "version": "2.4.2", - "dev": true, - "license": "MIT" - }, "node_modules/@types/offscreencanvas": { "version": "2019.7.1", "license": "MIT", @@ -2571,6 +2769,101 @@ "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", "dev": true }, + "node_modules/@vitest/expect": { + "version": "0.34.6", + "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-0.34.6.tgz", + "integrity": "sha512-QUzKpUQRc1qC7qdGo7rMK3AkETI7w18gTCUrsNnyjjJKYiuUB9+TQK3QnR1unhCnWRC0AbKv2omLGQDF/mIjOw==", + "dev": true, + "dependencies": { + "@vitest/spy": "0.34.6", + "@vitest/utils": "0.34.6", + "chai": "^4.3.10" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner": { + "version": "0.34.6", + "resolved": "https://registry.npmjs.org/@vitest/runner/-/runner-0.34.6.tgz", + "integrity": "sha512-1CUQgtJSLF47NnhN+F9X2ycxUP0kLHQ/JWvNHbeBfwW8CzEGgeskzNnHDyv1ieKTltuR6sdIHV+nmR6kPxQqzQ==", + "dev": true, + "dependencies": { + "@vitest/utils": "0.34.6", + "p-limit": "^4.0.0", + "pathe": "^1.1.1" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/runner/node_modules/p-limit": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-4.0.0.tgz", + "integrity": "sha512-5b0R4txpzjPWVw/cXXUResoD4hb6U/x9BH08L7nw+GN1sezDzPdxeRvpc9c433fZhBan/wusjbCsqwqm4EIBIQ==", + "dev": true, + "dependencies": { + "yocto-queue": "^1.0.0" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@vitest/runner/node_modules/yocto-queue": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-1.0.0.tgz", + "integrity": "sha512-9bnSc/HEW2uRy67wc+T8UwauLuPJVn28jb+GtJY16iiKWyvmYJRXVT4UamsAEGQfPohgr2q4Tq0sQbQlxTfi1g==", + "dev": true, + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@vitest/snapshot": { + "version": "0.34.6", + "resolved": "https://registry.npmjs.org/@vitest/snapshot/-/snapshot-0.34.6.tgz", + "integrity": "sha512-B3OZqYn6k4VaN011D+ve+AA4whM4QkcwcrwaKwAbyyvS/NB1hCWjFIBQxAQQSQir9/RtyAAGuq+4RJmbn2dH4w==", + "dev": true, + "dependencies": { + "magic-string": "^0.30.1", + "pathe": "^1.1.1", + "pretty-format": "^29.5.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/spy": { + "version": "0.34.6", + "resolved": "https://registry.npmjs.org/@vitest/spy/-/spy-0.34.6.tgz", + "integrity": "sha512-xaCvneSaeBw/cz8ySmF7ZwGvL0lBjfvqc1LpQ/vcdHEvpLn3Ff1vAvjw+CoGn0802l++5L/pxb7whwcWAw+DUQ==", + "dev": true, + "dependencies": { + "tinyspy": "^2.1.1" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/@vitest/utils": { + "version": "0.34.6", + "resolved": "https://registry.npmjs.org/@vitest/utils/-/utils-0.34.6.tgz", + "integrity": "sha512-IG5aDD8S6zlvloDsnzHw0Ut5xczlF+kv2BOTo+iXfPr54Yhi5qbVOgGB1hZaVq4iJ4C/MZ2J0y15IlsV/ZcI0A==", + "dev": true, + "dependencies": { + "diff-sequences": "^29.4.3", + "loupe": "^2.3.6", + "pretty-format": "^29.5.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, "node_modules/acorn": { "version": "8.11.2", "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.2.tgz", @@ -2592,6 +2885,15 @@ "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, + "node_modules/acorn-walk": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.0.tgz", + "integrity": "sha512-FS7hV565M5l1R08MXqo8odwMTB02C2UqzB17RVgu9EyuYFBqJZ3/ZY97sQD5FewVu1UyDFc1yztUDrAwT0EypA==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/ajv": { "version": "6.12.6", "dev": true, @@ -2670,12 +2972,13 @@ "node": ">=8" } }, - "node_modules/arrify": { - "version": "1.0.1", + "node_modules/assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true, - "license": "MIT", "engines": { - "node": ">=0.10.0" + "node": "*" } }, "node_modules/balanced-match": { @@ -2736,6 +3039,15 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/cac": { + "version": "6.7.14", + "resolved": "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz", + "integrity": "sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/call-bind": { "version": "1.0.2", "license": "MIT", @@ -2756,28 +3068,22 @@ "node": ">=6" } }, - "node_modules/camelcase": { - "version": "5.3.1", + "node_modules/chai": { + "version": "4.3.10", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.10.tgz", + "integrity": "sha512-0UXG04VuVbruMUYbJ6JctvH0YnC/4q3/AkT18q4NaITo91CUm0liMS9VqzT9vZhVQ/1eqPanMWjBM+Juhfb/9g==", "dev": true, - "license": "MIT", + "dependencies": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.3", + "deep-eql": "^4.1.3", + "get-func-name": "^2.0.2", + "loupe": "^2.3.6", + "pathval": "^1.1.1", + "type-detect": "^4.0.8" + }, "engines": { - "node": ">=6" - } - }, - "node_modules/camelcase-keys": { - "version": "6.2.2", - "dev": true, - "license": "MIT", - "dependencies": { - "camelcase": "^5.3.1", - "map-obj": "^4.0.0", - "quick-lru": "^4.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=4" } }, "node_modules/chalk": { @@ -2795,6 +3101,18 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/check-error": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", + "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.2" + }, + "engines": { + "node": "*" + } + }, "node_modules/ci-info": { "version": "3.9.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", @@ -2905,35 +3223,16 @@ } } }, - "node_modules/decamelize": { - "version": "1.2.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/decamelize-keys": { - "version": "1.1.1", + "node_modules/deep-eql": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", + "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", "dev": true, - "license": "MIT", "dependencies": { - "decamelize": "^1.1.0", - "map-obj": "^1.0.0" - }, - "engines": { - "node": ">=0.10.0" + "type-detect": "^4.0.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/decamelize-keys/node_modules/map-obj": { - "version": "1.0.1", - "dev": true, - "license": "MIT", "engines": { - "node": ">=0.10.0" + "node": ">=6" } }, "node_modules/deep-is": { @@ -2986,8 +3285,9 @@ }, "node_modules/diff-sequences": { "version": "29.6.3", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", + "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", "dev": true, - "license": "MIT", "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } @@ -3048,18 +3348,47 @@ "node": ">=10.0.0" } }, - "node_modules/error-ex": { - "version": "1.3.2", - "dev": true, - "license": "MIT", - "dependencies": { - "is-arrayish": "^0.2.1" - } - }, "node_modules/es6-promise-polyfill": { "version": "1.2.0", "license": "MIT" }, + "node_modules/esbuild": { + "version": "0.18.20", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.18.20.tgz", + "integrity": "sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==", + "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, + "engines": { + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/android-arm": "0.18.20", + "@esbuild/android-arm64": "0.18.20", + "@esbuild/android-x64": "0.18.20", + "@esbuild/darwin-arm64": "0.18.20", + "@esbuild/darwin-x64": "0.18.20", + "@esbuild/freebsd-arm64": "0.18.20", + "@esbuild/freebsd-x64": "0.18.20", + "@esbuild/linux-arm": "0.18.20", + "@esbuild/linux-arm64": "0.18.20", + "@esbuild/linux-ia32": "0.18.20", + "@esbuild/linux-loong64": "0.18.20", + "@esbuild/linux-mips64el": "0.18.20", + "@esbuild/linux-ppc64": "0.18.20", + "@esbuild/linux-riscv64": "0.18.20", + "@esbuild/linux-s390x": "0.18.20", + "@esbuild/linux-x64": "0.18.20", + "@esbuild/netbsd-x64": "0.18.20", + "@esbuild/openbsd-x64": "0.18.20", + "@esbuild/sunos-x64": "0.18.20", + "@esbuild/win32-arm64": "0.18.20", + "@esbuild/win32-ia32": "0.18.20", + "@esbuild/win32-x64": "0.18.20" + } + }, "node_modules/escape-string-regexp": { "version": "4.0.0", "dev": true, @@ -3137,88 +3466,6 @@ "eslint": ">=7.0.0" } }, - "node_modules/eslint-formatter-pretty": { - "version": "4.1.0", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/eslint": "^7.2.13", - "ansi-escapes": "^4.2.1", - "chalk": "^4.1.0", - "eslint-rule-docs": "^1.1.5", - "log-symbols": "^4.0.0", - "plur": "^4.0.0", - "string-width": "^4.2.0", - "supports-hyperlinks": "^2.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/@types/eslint": { - "version": "7.29.0", - "resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-7.29.0.tgz", - "integrity": "sha512-VNcvioYDH8/FxaeTKkM4/TiTwt6pBV9E3OfGmvaw8tPl0rrHCJ4Ll15HRT+pMiFAf/MLQvAzC+6RzUMEL9Ceng==", - "dev": true, - "dependencies": { - "@types/estree": "*", - "@types/json-schema": "*" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/ansi-escapes": { - "version": "4.3.2", - "dev": true, - "license": "MIT", - "dependencies": { - "type-fest": "^0.21.3" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/emoji-regex": { - "version": "8.0.0", - "dev": true, - "license": "MIT" - }, - "node_modules/eslint-formatter-pretty/node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/string-width": { - "version": "4.2.3", - "dev": true, - "license": "MIT", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/eslint-formatter-pretty/node_modules/type-fest": { - "version": "0.21.3", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/eslint-plugin-prettier": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.0.1.tgz", @@ -3257,11 +3504,6 @@ "@microsoft/tsdoc-config": "0.16.2" } }, - "node_modules/eslint-rule-docs": { - "version": "1.1.235", - "dev": true, - "license": "MIT" - }, "node_modules/eslint-scope": { "version": "7.2.2", "dev": true, @@ -3483,10 +3725,33 @@ "dev": true, "license": "ISC" }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "dev": true, + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, "node_modules/function-bind": { "version": "1.1.1", "license": "MIT" }, + "node_modules/get-func-name": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/get-intrinsic": { "version": "1.2.1", "license": "MIT", @@ -3599,14 +3864,6 @@ "uglify-js": "^3.1.4" } }, - "node_modules/hard-rejection": { - "version": "2.1.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/has": { "version": "1.0.4", "license": "MIT", @@ -3642,17 +3899,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/hosted-git-info": { - "version": "4.1.0", - "dev": true, - "license": "ISC", - "dependencies": { - "lru-cache": "^6.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/human-signals": { "version": "4.3.1", "dev": true, @@ -3707,14 +3953,6 @@ "node": ">=0.8.19" } }, - "node_modules/indent-string": { - "version": "4.0.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/inflight": { "version": "1.0.6", "dev": true, @@ -3729,19 +3967,6 @@ "dev": true, "license": "ISC" }, - "node_modules/irregular-plurals": { - "version": "3.5.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/is-arrayish": { - "version": "0.2.1", - "dev": true, - "license": "MIT" - }, "node_modules/is-ci": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/is-ci/-/is-ci-3.0.1.tgz", @@ -3843,14 +4068,6 @@ "node": ">=8" } }, - "node_modules/is-plain-obj": { - "version": "1.1.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/is-stream": { "version": "3.0.0", "dev": true, @@ -3862,17 +4079,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-unicode-supported": { - "version": "0.1.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/is-wsl": { "version": "2.2.0", "dev": true, @@ -3907,38 +4113,11 @@ "version": "1.1.1", "license": "MIT" }, - "node_modules/jest-diff": { - "version": "29.7.0", - "dev": true, - "license": "MIT", - "dependencies": { - "chalk": "^4.0.0", - "diff-sequences": "^29.6.3", - "jest-get-type": "^29.6.3", - "pretty-format": "^29.7.0" - }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, - "node_modules/jest-get-type": { - "version": "29.6.3", - "dev": true, - "license": "MIT", - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" - } - }, "node_modules/jju": { "version": "1.4.0", "dev": true, "license": "MIT" }, - "node_modules/js-tokens": { - "version": "4.0.0", - "dev": true, - "license": "MIT" - }, "node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", @@ -3956,11 +4135,6 @@ "dev": true, "license": "MIT" }, - "node_modules/json-parse-even-better-errors": { - "version": "2.3.1", - "dev": true, - "license": "MIT" - }, "node_modules/json-schema-traverse": { "version": "0.4.1", "dev": true, @@ -3971,6 +4145,12 @@ "dev": true, "license": "MIT" }, + "node_modules/jsonc-parser": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz", + "integrity": "sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==", + "dev": true + }, "node_modules/keyv": { "version": "4.5.4", "dev": true, @@ -3979,14 +4159,6 @@ "json-buffer": "3.0.1" } }, - "node_modules/kind-of": { - "version": "6.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/levn": { "version": "0.4.1", "dev": true, @@ -4007,11 +4179,6 @@ "node": ">=10" } }, - "node_modules/lines-and-columns": { - "version": "1.2.4", - "dev": true, - "license": "MIT" - }, "node_modules/lint-staged": { "version": "15.0.2", "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-15.0.2.tgz", @@ -4129,6 +4296,18 @@ "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==", "dev": true }, + "node_modules/local-pkg": { + "version": "0.4.3", + "resolved": "https://registry.npmjs.org/local-pkg/-/local-pkg-0.4.3.tgz", + "integrity": "sha512-SFppqq5p42fe2qcZQqqEOiVRXl+WCP1MdT6k7BDEW1j++sp5fIY+/fdRQitvKgB5BrBcmrs5m/L0v2FrU5MY1g==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/antfu" + } + }, "node_modules/locate-path": { "version": "6.0.0", "dev": true, @@ -4148,21 +4327,6 @@ "dev": true, "license": "MIT" }, - "node_modules/log-symbols": { - "version": "4.1.0", - "dev": true, - "license": "MIT", - "dependencies": { - "chalk": "^4.1.0", - "is-unicode-supported": "^0.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/log-update": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/log-update/-/log-update-5.0.1.tgz", @@ -4209,6 +4373,15 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/loupe": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", + "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.1" + } + }, "node_modules/lru-cache": { "version": "6.0.0", "dev": true, @@ -4220,55 +4393,20 @@ "node": ">=10" } }, - "node_modules/map-obj": { - "version": "4.3.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/meow": { - "version": "9.0.0", + "node_modules/magic-string": { + "version": "0.30.5", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.5.tgz", + "integrity": "sha512-7xlpfBaQaP/T6Vh8MO/EqXSW5En6INHEvEXQiuff7Gku0PWjU3uf6w/j9o7O+SpB5fOAkrI5HeoNgwjEO0pFsA==", "dev": true, - "license": "MIT", "dependencies": { - "@types/minimist": "^1.2.0", - "camelcase-keys": "^6.2.2", - "decamelize": "^1.2.0", - "decamelize-keys": "^1.1.0", - "hard-rejection": "^2.1.0", - "minimist-options": "4.1.0", - "normalize-package-data": "^3.0.0", - "read-pkg-up": "^7.0.1", - "redent": "^3.0.0", - "trim-newlines": "^3.0.0", - "type-fest": "^0.18.0", - "yargs-parser": "^20.2.3" + "@jridgewell/sourcemap-codec": "^1.4.15" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=12" } }, - "node_modules/meow/node_modules/type-fest": { - "version": "0.18.1", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/merge-stream": { - "version": "2.0.0", + "node_modules/merge-stream": { + "version": "2.0.0", "dev": true, "license": "MIT" }, @@ -4303,14 +4441,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/min-indent": { - "version": "1.0.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, "node_modules/mini-signals": { "version": "1.2.0", "license": "MIT" @@ -4333,23 +4463,40 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/minimist-options": { - "version": "4.1.0", + "node_modules/mlly": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.4.2.tgz", + "integrity": "sha512-i/Ykufi2t1EZ6NaPLdfnZk2AX8cs0d+mTzVKuPfqPKPatxLApaBoxJQ9x1/uckXtrS/U5oisPMDkNs0yQTaBRg==", "dev": true, - "license": "MIT", "dependencies": { - "arrify": "^1.0.1", - "is-plain-obj": "^1.1.0", - "kind-of": "^6.0.3" - }, - "engines": { - "node": ">= 6" + "acorn": "^8.10.0", + "pathe": "^1.1.1", + "pkg-types": "^1.0.3", + "ufo": "^1.3.0" } }, "node_modules/ms": { "version": "2.1.2", "license": "MIT" }, + "node_modules/nanoid": { + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", + "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "bin": { + "nanoid": "bin/nanoid.cjs" + }, + "engines": { + "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + } + }, "node_modules/natural-compare": { "version": "1.4.0", "dev": true, @@ -4359,20 +4506,6 @@ "version": "2.6.2", "license": "MIT" }, - "node_modules/normalize-package-data": { - "version": "3.0.3", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "hosted-git-info": "^4.0.1", - "is-core-module": "^2.5.0", - "semver": "^7.3.4", - "validate-npm-package-license": "^3.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/npm-run-path": { "version": "5.1.0", "dev": true, @@ -4499,14 +4632,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/p-try": { - "version": "2.2.0", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -4519,23 +4644,6 @@ "node": ">=6" } }, - "node_modules/parse-json": { - "version": "5.2.0", - "dev": true, - "license": "MIT", - "dependencies": { - "@babel/code-frame": "^7.0.0", - "error-ex": "^1.3.1", - "json-parse-even-better-errors": "^2.3.0", - "lines-and-columns": "^1.1.6" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/parse-uri": { "version": "1.0.8", "license": "MIT", @@ -4580,6 +4688,21 @@ "node": ">=8" } }, + "node_modules/pathe": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pathe/-/pathe-1.1.1.tgz", + "integrity": "sha512-d+RQGp0MAYTIaDBIMmOfMwz3E+LOZnxx1HZd5R18mmCZY0QBlK0LDZfPc8FW8Ed2DlvsuE6PRjroDY+wg4+j/Q==", + "dev": true + }, + "node_modules/pathval": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/picocolors": { "version": "1.0.0", "dev": true, @@ -4737,18 +4860,43 @@ "url": "^0.11.0" } }, - "node_modules/plur": { - "version": "4.0.0", + "node_modules/pkg-types": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/pkg-types/-/pkg-types-1.0.3.tgz", + "integrity": "sha512-nN7pYi0AQqJnoLPC9eHFQ8AcyaixBUOwvqc5TDnIKCMEE6I0y8P7OKA7fPexsXGCGxQDl/cmrLAp26LhcwxZ4A==", "dev": true, - "license": "MIT", "dependencies": { - "irregular-plurals": "^3.2.0" + "jsonc-parser": "^3.2.0", + "mlly": "^1.2.0", + "pathe": "^1.1.0" + } + }, + "node_modules/postcss": { + "version": "8.4.31", + "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.31.tgz", + "integrity": "sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==", + "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/postcss/" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/postcss" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "dependencies": { + "nanoid": "^3.3.6", + "picocolors": "^1.0.0", + "source-map-js": "^1.0.2" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": "^10 || ^12 || >=14" } }, "node_modules/prelude-ls": { @@ -4786,8 +4934,9 @@ }, "node_modules/pretty-format": { "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", "dev": true, - "license": "MIT", "dependencies": { "@jest/schemas": "^29.6.3", "ansi-styles": "^5.0.0", @@ -4799,8 +4948,9 @@ }, "node_modules/pretty-format/node_modules/ansi-styles": { "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", "dev": true, - "license": "MIT", "engines": { "node": ">=10" }, @@ -4921,148 +5071,11 @@ ], "license": "MIT" }, - "node_modules/quick-lru": { - "version": "4.0.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/react-is": { "version": "18.2.0", - "dev": true, - "license": "MIT" - }, - "node_modules/read-pkg": { - "version": "5.2.0", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/normalize-package-data": "^2.4.0", - "normalize-package-data": "^2.5.0", - "parse-json": "^5.0.0", - "type-fest": "^0.6.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/read-pkg-up": { - "version": "7.0.1", - "dev": true, - "license": "MIT", - "dependencies": { - "find-up": "^4.1.0", - "read-pkg": "^5.2.0", - "type-fest": "^0.8.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/read-pkg-up/node_modules/find-up": { - "version": "4.1.0", - "dev": true, - "license": "MIT", - "dependencies": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/read-pkg-up/node_modules/locate-path": { - "version": "5.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "p-locate": "^4.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/read-pkg-up/node_modules/p-limit": { - "version": "2.3.0", - "dev": true, - "license": "MIT", - "dependencies": { - "p-try": "^2.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/read-pkg-up/node_modules/p-locate": { - "version": "4.1.0", - "dev": true, - "license": "MIT", - "dependencies": { - "p-limit": "^2.2.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/read-pkg-up/node_modules/type-fest": { - "version": "0.8.1", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=8" - } - }, - "node_modules/read-pkg/node_modules/hosted-git-info": { - "version": "2.8.9", - "dev": true, - "license": "ISC" - }, - "node_modules/read-pkg/node_modules/normalize-package-data": { - "version": "2.5.0", - "dev": true, - "license": "BSD-2-Clause", - "dependencies": { - "hosted-git-info": "^2.1.4", - "resolve": "^1.10.0", - "semver": "2 || 3 || 4 || 5", - "validate-npm-package-license": "^3.0.1" - } - }, - "node_modules/read-pkg/node_modules/semver": { - "version": "5.7.2", - "dev": true, - "license": "ISC", - "bin": { - "semver": "bin/semver" - } - }, - "node_modules/read-pkg/node_modules/type-fest": { - "version": "0.6.0", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=8" - } - }, - "node_modules/redent": { - "version": "3.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "indent-string": "^4.0.0", - "strip-indent": "^3.0.0" - }, - "engines": { - "node": ">=8" - } + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", + "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==", + "dev": true }, "node_modules/resolve": { "version": "1.19.0", @@ -5162,6 +5175,22 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rollup": { + "version": "3.29.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-3.29.4.tgz", + "integrity": "sha512-oWzmBZwvYrU0iJHtDmhsm662rC15FRXmcjCk1xD771dFDx5jJ02ufAQQTn0etB2emNk4J9EZg/yWKpsn9BWGRw==", + "dev": true, + "bin": { + "rollup": "dist/bin/rollup" + }, + "engines": { + "node": ">=14.18.0", + "npm": ">=8.0.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, "node_modules/run-applescript": { "version": "5.0.0", "dev": true, @@ -5325,6 +5354,12 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/siginfo": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/siginfo/-/siginfo-2.0.0.tgz", + "integrity": "sha512-ybx0WO1/8bSBLEWXZvEd7gMW3Sn3JFlW3TvX1nREbDLRNQNaeNN8WK0meBwPdAaOI7TtRRRJn/Es1zhrrCHu7g==", + "dev": true + }, "node_modules/signal-exit": { "version": "3.0.7", "dev": true, @@ -5397,33 +5432,26 @@ "node": ">=0.10.0" } }, - "node_modules/spdx-correct": { - "version": "3.2.0", + "node_modules/source-map-js": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz", + "integrity": "sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==", "dev": true, - "license": "Apache-2.0", - "dependencies": { - "spdx-expression-parse": "^3.0.0", - "spdx-license-ids": "^3.0.0" + "engines": { + "node": ">=0.10.0" } }, - "node_modules/spdx-exceptions": { - "version": "2.3.0", - "dev": true, - "license": "CC-BY-3.0" - }, - "node_modules/spdx-expression-parse": { - "version": "3.0.1", - "dev": true, - "license": "MIT", - "dependencies": { - "spdx-exceptions": "^2.1.0", - "spdx-license-ids": "^3.0.0" - } + "node_modules/stackback": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/stackback/-/stackback-0.0.2.tgz", + "integrity": "sha512-1XMJE5fQo1jGH6Y/7ebnwPOBEkIEnT4QF32d5R1+VXdXveM0IBMJt8zfaxX1P3QhVwrYe+576+jkANtSS2mBbw==", + "dev": true }, - "node_modules/spdx-license-ids": { - "version": "3.0.16", - "dev": true, - "license": "CC0-1.0" + "node_modules/std-env": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/std-env/-/std-env-3.4.3.tgz", + "integrity": "sha512-f9aPhy8fYBuMN+sNfakZV18U39PbalgjXG3lLB9WkaYTxijru61wb57V9wxxNthXM5Sd88ETBWi29qLAsHO52Q==", + "dev": true }, "node_modules/string-argv": { "version": "0.3.2", @@ -5499,17 +5527,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/strip-indent": { - "version": "3.0.0", - "dev": true, - "license": "MIT", - "dependencies": { - "min-indent": "^1.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -5522,24 +5539,24 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/supports-color": { - "version": "7.2.0", + "node_modules/strip-literal": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/strip-literal/-/strip-literal-1.3.0.tgz", + "integrity": "sha512-PugKzOsyXpArk0yWmUwqOZecSO0GH0bPoctLcqNDH9J04pVW3lflYE0ujElBGTloevcxF5MofAOZ7C5l2b+wLg==", "dev": true, - "license": "MIT", "dependencies": { - "has-flag": "^4.0.0" + "acorn": "^8.10.0" }, - "engines": { - "node": ">=8" + "funding": { + "url": "https://github.com/sponsors/antfu" } }, - "node_modules/supports-hyperlinks": { - "version": "2.3.0", + "node_modules/supports-color": { + "version": "7.2.0", "dev": true, "license": "MIT", "dependencies": { - "has-flag": "^4.0.0", - "supports-color": "^7.0.0" + "has-flag": "^4.0.0" }, "engines": { "node": ">=8" @@ -5565,10 +5582,34 @@ "dev": true, "license": "MIT" }, + "node_modules/tinybench": { + "version": "2.5.1", + "resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.5.1.tgz", + "integrity": "sha512-65NKvSuAVDP/n4CqH+a9w2kTlLReS9vhsAP06MWx+/89nMinJyB2icyl58RIcqCmIggpojIGeuJGhjU1aGMBSg==", + "dev": true + }, "node_modules/tinymce": { "version": "6.7.0", "license": "MIT" }, + "node_modules/tinypool": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/tinypool/-/tinypool-0.7.0.tgz", + "integrity": "sha512-zSYNUlYSMhJ6Zdou4cJwo/p7w5nmAH17GRfU/ui3ctvjXFErXXkruT4MWW6poDeXgCaIBlGLrfU6TbTXxyGMww==", + "dev": true, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/tinyspy": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/tinyspy/-/tinyspy-2.2.0.tgz", + "integrity": "sha512-d2eda04AN/cPOR89F7Xv5bK/jrQEhmcLFe6HFldoeO9AJtps+fqEnh486vnT/8y4bw38pSyxDcTCAq+Ks2aJTg==", + "dev": true, + "engines": { + "node": ">=14.0.0" + } + }, "node_modules/titleize": { "version": "3.0.0", "dev": true, @@ -5591,14 +5632,6 @@ "node": ">=8.0" } }, - "node_modules/trim-newlines": { - "version": "3.0.1", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/ts-api-utils": { "version": "1.0.3", "dev": true, @@ -5610,26 +5643,6 @@ "typescript": ">=4.2.0" } }, - "node_modules/tsd": { - "version": "0.29.0", - "dev": true, - "license": "MIT", - "dependencies": { - "@tsd/typescript": "~5.2.2", - "eslint-formatter-pretty": "^4.1.0", - "globby": "^11.0.1", - "jest-diff": "^29.0.3", - "meow": "^9.0.0", - "path-exists": "^4.0.0", - "read-pkg-up": "^7.0.0" - }, - "bin": { - "tsd": "dist/cli.js" - }, - "engines": { - "node": ">=14.16" - } - }, "node_modules/tslib": { "version": "2.6.2", "dev": true, @@ -5646,6 +5659,15 @@ "node": ">= 0.8.0" } }, + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/type-fest": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", @@ -5670,6 +5692,12 @@ "node": ">=14.17" } }, + "node_modules/ufo": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.3.1.tgz", + "integrity": "sha512-uY/99gMLIOlJPwATcMVYfqDSxUR9//AUcgZMzwfSTJPDKzA1S8mX4VLqa+fiAtveraQUBCz4FFcwVZBGbwBXIw==", + "dev": true + }, "node_modules/uglify-js": { "version": "3.17.4", "license": "BSD-2-Clause", @@ -5709,13 +5737,159 @@ "version": "1.4.1", "license": "MIT" }, - "node_modules/validate-npm-package-license": { - "version": "3.0.4", + "node_modules/vite": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/vite/-/vite-4.5.0.tgz", + "integrity": "sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==", + "dev": true, + "dependencies": { + "esbuild": "^0.18.10", + "postcss": "^8.4.27", + "rollup": "^3.27.1" + }, + "bin": { + "vite": "bin/vite.js" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/vitejs/vite?sponsor=1" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + }, + "peerDependencies": { + "@types/node": ">= 14", + "less": "*", + "lightningcss": "^1.21.0", + "sass": "*", + "stylus": "*", + "sugarss": "*", + "terser": "^5.4.0" + }, + "peerDependenciesMeta": { + "@types/node": { + "optional": true + }, + "less": { + "optional": true + }, + "lightningcss": { + "optional": true + }, + "sass": { + "optional": true + }, + "stylus": { + "optional": true + }, + "sugarss": { + "optional": true + }, + "terser": { + "optional": true + } + } + }, + "node_modules/vite-node": { + "version": "0.34.6", + "resolved": "https://registry.npmjs.org/vite-node/-/vite-node-0.34.6.tgz", + "integrity": "sha512-nlBMJ9x6n7/Amaz6F3zJ97EBwR2FkzhBRxF5e+jE6LA3yi6Wtc2lyTij1OnDMIr34v5g/tVQtsVAzhT0jc5ygA==", + "dev": true, + "dependencies": { + "cac": "^6.7.14", + "debug": "^4.3.4", + "mlly": "^1.4.0", + "pathe": "^1.1.1", + "picocolors": "^1.0.0", + "vite": "^3.0.0 || ^4.0.0 || ^5.0.0-0" + }, + "bin": { + "vite-node": "vite-node.mjs" + }, + "engines": { + "node": ">=v14.18.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + } + }, + "node_modules/vitest": { + "version": "0.34.6", + "resolved": "https://registry.npmjs.org/vitest/-/vitest-0.34.6.tgz", + "integrity": "sha512-+5CALsOvbNKnS+ZHMXtuUC7nL8/7F1F2DnHGjSsszX8zCjWSSviphCb/NuS9Nzf4Q03KyyDRBAXhF/8lffME4Q==", "dev": true, - "license": "Apache-2.0", "dependencies": { - "spdx-correct": "^3.0.0", - "spdx-expression-parse": "^3.0.0" + "@types/chai": "^4.3.5", + "@types/chai-subset": "^1.3.3", + "@types/node": "*", + "@vitest/expect": "0.34.6", + "@vitest/runner": "0.34.6", + "@vitest/snapshot": "0.34.6", + "@vitest/spy": "0.34.6", + "@vitest/utils": "0.34.6", + "acorn": "^8.9.0", + "acorn-walk": "^8.2.0", + "cac": "^6.7.14", + "chai": "^4.3.10", + "debug": "^4.3.4", + "local-pkg": "^0.4.3", + "magic-string": "^0.30.1", + "pathe": "^1.1.1", + "picocolors": "^1.0.0", + "std-env": "^3.3.3", + "strip-literal": "^1.0.1", + "tinybench": "^2.5.0", + "tinypool": "^0.7.0", + "vite": "^3.1.0 || ^4.0.0 || ^5.0.0-0", + "vite-node": "0.34.6", + "why-is-node-running": "^2.2.2" + }, + "bin": { + "vitest": "vitest.mjs" + }, + "engines": { + "node": ">=v14.18.0" + }, + "funding": { + "url": "https://opencollective.com/vitest" + }, + "peerDependencies": { + "@edge-runtime/vm": "*", + "@vitest/browser": "*", + "@vitest/ui": "*", + "happy-dom": "*", + "jsdom": "*", + "playwright": "*", + "safaridriver": "*", + "webdriverio": "*" + }, + "peerDependenciesMeta": { + "@edge-runtime/vm": { + "optional": true + }, + "@vitest/browser": { + "optional": true + }, + "@vitest/ui": { + "optional": true + }, + "happy-dom": { + "optional": true + }, + "jsdom": { + "optional": true + }, + "playwright": { + "optional": true + }, + "safaridriver": { + "optional": true + }, + "webdriverio": { + "optional": true + } } }, "node_modules/w3c-keyname": { @@ -5736,6 +5910,22 @@ "node": ">= 8" } }, + "node_modules/why-is-node-running": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-2.2.2.tgz", + "integrity": "sha512-6tSwToZxTOcotxHeA+qGCq1mVzKR3CwcJGmVcY+QE8SHy6TnpFnh8PAvPNHYr7EcuVeG0QSMxtYCuO1ta/G/oA==", + "dev": true, + "dependencies": { + "siginfo": "^2.0.0", + "stackback": "0.0.2" + }, + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/wordwrap": { "version": "1.0.0", "license": "MIT" @@ -5840,14 +6030,6 @@ "node": ">= 14" } }, - "node_modules/yargs-parser": { - "version": "20.2.9", - "dev": true, - "license": "ISC", - "engines": { - "node": ">=10" - } - }, "node_modules/yocto-queue": { "version": "0.1.0", "dev": true, diff --git a/package.json b/package.json index 35781e3c5..498a47c90 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "lint:fix": "eslint --fix --ext .d.ts,.test-d.ts .", "lint:ci": "eslint --ext .d.ts,.test-d.ts .", "eslint:report": "eslint --output-file eslint_report.json --format json --ext .d.ts,.test-d.ts .", - "test": "tsd", + "test": "vitest typecheck", "typecheck": "./node_modules/typescript/bin/tsc", "prepare": "is-ci || husky install" }, @@ -87,8 +87,8 @@ "is-ci": "^3.0.1", "lint-staged": "^15.0.1", "prettier": "^3.0.3", - "tsd": "~0.29", - "typescript": "~5.2" + "typescript": "~5.2", + "vitest": "^0.34.6" }, "husky": { "hooks": { diff --git a/src/foundry/client/apps/hud/chatbubble.d.ts b/src/foundry/client/apps/hud/chatbubble.d.ts index 20d86feea..cc9467ee2 100644 --- a/src/foundry/client/apps/hud/chatbubble.d.ts +++ b/src/foundry/client/apps/hud/chatbubble.d.ts @@ -1,111 +1,113 @@ import type { Socket } from "socket.io-client"; -/** - * The Chat Bubble Class - * This application displays a temporary message sent from a particular Token in the active Scene. - * The message is displayed on the HUD layer just above the Token. - */ -declare class ChatBubbles { - constructor(); - +declare global { /** - * @defaultValue `"templates/hud/chat-bubble.html"` + * The Chat Bubble Class + * This application displays a temporary message sent from a particular Token in the active Scene. + * The message is displayed on the HUD layer just above the Token. */ - template: string; + declare class ChatBubbles { + constructor(); - /** - * Track active Chat Bubbles - * @defaultValue `{}` - * @remarks This is never used - */ - bubbles: object; + /** + * @defaultValue `"templates/hud/chat-bubble.html"` + */ + template: string; - /** - * Track which Token was most recently panned to highlight - * Use this to avoid repeat panning - * @defaultValue `null` - * @internal - */ - protected _panned: Token | null; + /** + * Track active Chat Bubbles + * @defaultValue `{}` + * @remarks This is never used + */ + bubbles: object; - /** - * A reference to the chat bubbles HTML container in which rendered bubbles should live - */ - get container(): JQuery; + /** + * Track which Token was most recently panned to highlight + * Use this to avoid repeat panning + * @defaultValue `null` + * @internal + */ + protected _panned: Token | null; - /** - * Create a chat bubble message for a certain token which is synchronized for display across all connected clients. - * @param token - The speaking Token Document - * @param message - The spoken message text - * @param options - Options which affect the bubble appearance - */ - broadcast(token: TokenDocument, message: string, options: ChatBubbles.ChatBubbleOptions): Promise; + /** + * A reference to the chat bubbles HTML container in which rendered bubbles should live + */ + get container(): JQuery; - /** - * Speak a message as a particular Token, displaying it as a chat bubble - * @param token - The speaking Token - * @param message - The spoken message text - * @param emote - Whether to style the speech bubble as an emote - * @returns A Promise which resolves once the chat bubble has been created - */ - say(token: Token, message: string, { emote }?: { emote?: boolean }): Promise; + /** + * Create a chat bubble message for a certain token which is synchronized for display across all connected clients. + * @param token - The speaking Token Document + * @param message - The spoken message text + * @param options - Options which affect the bubble appearance + */ + broadcast(token: TokenDocument, message: string, options: ChatBubbles.ChatBubbleOptions): Promise; - /** - * Activate Socket event listeners which apply to the ChatBubbles UI. - * @param socket - The active web socket connection - */ - protected static _activateSocketListeners(socket: Socket): Promise; + /** + * Speak a message as a particular Token, displaying it as a chat bubble + * @param token - The speaking Token + * @param message - The spoken message text + * @param emote - Whether to style the speech bubble as an emote + * @returns A Promise which resolves once the chat bubble has been created + */ + say(token: Token, message: string, { emote }?: { emote?: boolean }): Promise; - /** - * Clear any existing chat bubble for a certain Token - * @internal - */ - protected _clearBubble(token: Token): Promise; + /** + * Activate Socket event listeners which apply to the ChatBubbles UI. + * @param socket - The active web socket connection + */ + protected static _activateSocketListeners(socket: Socket): Promise; - /** - * Render the HTML template for the chat bubble - * @param data - Template data - * @returns The rendered HTML - * @internal - */ - protected _renderHTML(data: { token: Token; message: string; emote: boolean }): Promise; + /** + * Clear any existing chat bubble for a certain Token + * @internal + */ + protected _clearBubble(token: Token): Promise; - /** - * Before displaying the chat message, determine it's constrained and unconstrained dimensions - * @param message - The message content - * @returns The rendered message dimensions - * @internal - */ - protected _getMessageDimensions(message: string): ChatBubbles.Dimensions; + /** + * Render the HTML template for the chat bubble + * @param data - Template data + * @returns The rendered HTML + * @internal + */ + protected _renderHTML(data: { token: Token; message: string; emote: boolean }): Promise; - /** - * Assign styling parameters to the chat bubble, toggling either a left or right display (randomly) - * @internal - */ - protected _setPosition(token: Token, html: JQuery, dimensions: ChatBubbles.Dimensions): void; + /** + * Before displaying the chat message, determine it's constrained and unconstrained dimensions + * @param message - The message content + * @returns The rendered message dimensions + * @internal + */ + protected _getMessageDimensions(message: string): ChatBubbles.Dimensions; - /** - * Determine the length of time for which to display a chat bubble. - * Research suggests that average reading speed is 200 words per minute. - * Since these are short-form messages, we multiply reading speed by 1.5. - * Clamp the result between 1 second (minimum) and 20 seconds (maximum) - * - * @param html - The HTML message - * @returns The number of milliseconds for which to display the message - */ - protected _getDuration(html: JQuery): number; -} + /** + * Assign styling parameters to the chat bubble, toggling either a left or right display (randomly) + * @internal + */ + protected _setPosition(token: Token, html: JQuery, dimensions: ChatBubbles.Dimensions): void; -declare namespace ChatBubbles { - interface Dimensions { - width: number; - height: number; - unconstrained: number; + /** + * Determine the length of time for which to display a chat bubble. + * Research suggests that average reading speed is 200 words per minute. + * Since these are short-form messages, we multiply reading speed by 1.5. + * Clamp the result between 1 second (minimum) and 20 seconds (maximum) + * + * @param html - The HTML message + * @returns The number of milliseconds for which to display the message + */ + protected _getDuration(html: JQuery): number; } - interface ChatBubbleOptions { - cssClasses?: string; - pan: boolean; - requireVisible: false; + declare namespace ChatBubbles { + interface Dimensions { + width: number; + height: number; + unconstrained: number; + } + + interface ChatBubbleOptions { + cssClasses?: string; + pan: boolean; + requireVisible: false; + } } } diff --git a/test-d/foundry/client/apps/app.test-d.ts b/test-d/foundry/client/apps/app.test-d.ts deleted file mode 100644 index aab5b5449..000000000 --- a/test-d/foundry/client/apps/app.test-d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expectType } from "tsd"; - -expectType(Application.defaultOptions); - -const app = new (class extends Application {})(); -expectType(app.id); -expectType(app.element); -expectType(app.appId); -expectType(app.popOut); -expectType(app.template); -expectType(app.title); -expectType(app.rendered); - -expectType(app.bringToTop()); -expectType>(app.getData()); -expectType(app.options); -expectType>(app.close({ force: false })); -expectType>(app.close()); -expectType(app.render()); -expectType(app.render(true)); -expectType(app.render(false, { height: "auto" })); diff --git a/test-d/foundry/client/apps/forms/actor.test-d.ts b/test-d/foundry/client/apps/forms/actor.test-d.ts deleted file mode 100644 index cd3175076..000000000 --- a/test-d/foundry/client/apps/forms/actor.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const actorSheet = new ActorSheet(new Actor({ name: "Some dude", type: "character" })); -expectType(actorSheet.object); -expectType(actorSheet.actor); -expectType(actorSheet.token); diff --git a/test-d/foundry/client/apps/forms/combatant-config.test-d.ts b/test-d/foundry/client/apps/forms/combatant-config.test-d.ts deleted file mode 100644 index d0d04009f..000000000 --- a/test-d/foundry/client/apps/forms/combatant-config.test-d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expectError, expectType } from "tsd"; - -declare const combatant: Combatant; -declare const baseCombatant: foundry.documents.BaseCombatant; - -expectType(CombatantConfig.defaultOptions); - -expectError(new CombatantConfig(baseCombatant)); - -const sheet = new CombatantConfig(combatant); -expectType(sheet.document); -expectType(sheet.object); -expectType(sheet.title); -expectType(sheet.options); diff --git a/test-d/foundry/client/apps/forms/effect-config.test-d.ts b/test-d/foundry/client/apps/forms/effect-config.test-d.ts deleted file mode 100644 index c89af8e66..000000000 --- a/test-d/foundry/client/apps/forms/effect-config.test-d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new ActiveEffectConfig(new foundry.documents.BaseActiveEffect())); - -const config = new ActiveEffectConfig(new ActiveEffect()); -expectType(config.object); -expectType>(config.options); - -const withCustomOptions = new ActiveEffectConfig & { custom: true }>( - new ActiveEffect(), -); -expectType & { custom: true }>(withCustomOptions.options); diff --git a/test-d/foundry/client/apps/forms/item.test-d.ts b/test-d/foundry/client/apps/forms/item.test-d.ts deleted file mode 100644 index d48aae140..000000000 --- a/test-d/foundry/client/apps/forms/item.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectType } from "tsd"; - -const itemSheet = new ItemSheet(new Item({ name: "Heavy armor", type: "armor" })); -expectType(itemSheet.object); -expectType(itemSheet.item); diff --git a/test-d/foundry/client/apps/forms/journal-sheet.test-d.ts b/test-d/foundry/client/apps/forms/journal-sheet.test-d.ts deleted file mode 100644 index 93e95ef68..000000000 --- a/test-d/foundry/client/apps/forms/journal-sheet.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectType } from "tsd"; - -const journalSheet = new JournalSheet(new JournalEntry({ name: "Some Journal Entry" })); -expectType(journalSheet.object); -expectType(journalSheet.render(true, { sheetMode: "image" })); diff --git a/test-d/foundry/client/apps/forms/macro-config.test-d.ts b/test-d/foundry/client/apps/forms/macro-config.test-d.ts deleted file mode 100644 index a44b8822c..000000000 --- a/test-d/foundry/client/apps/forms/macro-config.test-d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { expectError, expectType } from "tsd"; - -declare const baseMacro: foundry.documents.BaseMacro; -declare const macro: Macro; - -expectError(new MacroConfig(baseMacro)); - -const config = new MacroConfig(macro); -expectType(config.object); - -const withCustomOptions = new MacroConfig & { custom: true }>(macro); -expectType & { custom: true }>(withCustomOptions.options); diff --git a/test-d/foundry/client/apps/forms/user-config.test-d.ts b/test-d/foundry/client/apps/forms/user-config.test-d.ts deleted file mode 100644 index d7accaa5c..000000000 --- a/test-d/foundry/client/apps/forms/user-config.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new UserConfig(new foundry.documents.BaseUser())); - -const config = new UserConfig(new User()); -expectType(config.object); - -const withCustomOptions = new UserConfig & { custom: true }>(new User()); -expectType & { custom: true }>(withCustomOptions.options); diff --git a/test-d/foundry/client/apps/hud/chatbubble.test-d.ts b/test-d/foundry/client/apps/hud/chatbubble.test-d.ts deleted file mode 100644 index 3c915188d..000000000 --- a/test-d/foundry/client/apps/hud/chatbubble.test-d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expectType } from "tsd"; - -declare const token: Token; - -const bubbles = new ChatBubbles(); -expectType(bubbles.template); -expectType(bubbles.bubbles); -expectType(bubbles.container); -expectType>(bubbles.say(token, "Hello World!")); -expectType>(bubbles.say(token, "Hello World!", { emote: true })); diff --git a/test-d/foundry/client/apps/hud/container.test-d.ts b/test-d/foundry/client/apps/hud/container.test-d.ts deleted file mode 100644 index f32f598c5..000000000 --- a/test-d/foundry/client/apps/hud/container.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; - -const display = new HeadsUpDisplay(); -expectType(display.token); -expectType(display.tile); -expectType(display.drawing); -expectType(display.bubbles); -expectType>(display.getData()); -expectType(display.align()); diff --git a/test-d/foundry/client/apps/hud/controls.test-d.ts b/test-d/foundry/client/apps/hud/controls.test-d.ts deleted file mode 100644 index 00767e941..000000000 --- a/test-d/foundry/client/apps/hud/controls.test-d.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { expectAssignable, expectNotAssignable, expectType } from "tsd"; - -expectType(new SceneControls()); -expectType(new SceneControls({ width: null })); -expectType(SceneControls.defaultOptions.width); - -const controls = new SceneControls(); -expectType(controls.initialize()); -expectType(controls.initialize({ control: "token" })); -expectType(controls.initialize({ layer: "tokens" })); -expectType(controls.initialize({ tool: "select" })); - -expectType(controls.controls); -expectType(controls.controls.map((each) => each.tools)); - -expectAssignable({ - name: "foo", - title: "bar", - icon: "baz", - onClick: () => undefined, -}); -expectAssignable({ - name: "foo", - title: "bar", - icon: "baz", - toggle: false, - onClick: () => undefined, -}); -expectAssignable({ - name: "foo", - title: "bar", - icon: "baz", - button: true, - onClick: () => undefined, -}); -expectAssignable({ - name: "foo", - title: "bar", - icon: "baz", - toggle: true, - onClick: (toggle: boolean) => toggle, -}); -expectNotAssignable({ - name: "foo", - title: "bar", - icon: "baz", - toggle: false, - onClick: (toggle: boolean) => toggle, -}); -expectNotAssignable({ - name: "foo", - title: "bar", - icon: "baz", - onClick: (toggle: boolean) => toggle, -}); diff --git a/test-d/foundry/client/apps/hud/hotbar.test-d.ts b/test-d/foundry/client/apps/hud/hotbar.test-d.ts deleted file mode 100644 index 3f21c5e60..000000000 --- a/test-d/foundry/client/apps/hud/hotbar.test-d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expectType } from "tsd"; - -const hotbar = new Hotbar(); -expectType(hotbar.page); -expectType(hotbar.macros); -expectType>(hotbar.getData()); - -expectType>(hotbar.collapse()); -expectType>(hotbar.expand()); -expectType(hotbar.changePage()); -expectType(hotbar.changePage(5)); -expectType(hotbar.cyclePage()); -expectType(hotbar.cyclePage(1)); -expectType(hotbar.cyclePage(-1)); diff --git a/test-d/foundry/client/apps/hud/hud.test-d.ts b/test-d/foundry/client/apps/hud/hud.test-d.ts deleted file mode 100644 index 34d68236f..000000000 --- a/test-d/foundry/client/apps/hud/hud.test-d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expectType } from "tsd"; - -class MyPlaceableHud extends BasePlaceableHUD {} - -declare const token: Token; - -const hud = new MyPlaceableHud(); -expectType(hud.object); - -expectType | undefined>(hud.layer); -expectType(hud.bind(token)); -expectType(hud.clear()); - -expectType>(hud.getData()); diff --git a/test-d/foundry/client/apps/hud/menu.test-d.ts b/test-d/foundry/client/apps/hud/menu.test-d.ts deleted file mode 100644 index fa1e4068c..000000000 --- a/test-d/foundry/client/apps/hud/menu.test-d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { expectType } from "tsd"; - -const menu = new MainMenu(); - -expectType(menu.toggle()); - -const item = menu.items.reload; -if (item) { - expectType(item.label); - expectType(item.icon); - expectType(item.enabled); - expectType<() => void>(item.onClick); -} diff --git a/test-d/foundry/client/apps/i18n.test-d.ts b/test-d/foundry/client/apps/i18n.test-d.ts deleted file mode 100644 index ba67d84e5..000000000 --- a/test-d/foundry/client/apps/i18n.test-d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { expectType } from "tsd"; - -type Translations = { - [K: string]: string | Translations; -}; - -new Localization(); -const localization = new Localization("en.core"); -expectType(localization.lang); -expectType(localization.defaultModule); -expectType(localization.translations); -expectType>(localization.initialize()); -expectType>(localization.setLanguage("de")); -expectType(localization.has("WORLD.DetailTab")); -expectType(localization.has("WORLD.DetailTab", true)); -expectType(localization.localize("WORLD.DetailTab")); -expectType(localization.format("DICE.ErrorNonNumeric")); -expectType(localization.format("DICE.ErrorNonNumeric", { formula: "2d10" })); diff --git a/test-d/foundry/client/apps/placeables/drawing-hud.test-d.ts b/test-d/foundry/client/apps/placeables/drawing-hud.test-d.ts deleted file mode 100644 index f2715c9c6..000000000 --- a/test-d/foundry/client/apps/placeables/drawing-hud.test-d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expectType } from "tsd"; - -declare const drawing: Drawing; - -const hud = new DrawingHUD(); -expectType | undefined>(hud.layer); -expectType(hud.object); -hud.bind(drawing); -expectType>(hud.getData()); -expectType(hud.setPosition()); diff --git a/test-d/foundry/client/apps/placeables/sound-config.test-d.ts b/test-d/foundry/client/apps/placeables/sound-config.test-d.ts deleted file mode 100644 index e69f10bda..000000000 --- a/test-d/foundry/client/apps/placeables/sound-config.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; - -declare const doc: AmbientSoundDocument; - -expectType>(AmbientSoundConfig.defaultOptions); - -const config = new AmbientSoundConfig(doc); -expectType(config.title); -expectType>(config.close()); diff --git a/test-d/foundry/client/apps/placeables/tile-config.test-d.ts b/test-d/foundry/client/apps/placeables/tile-config.test-d.ts deleted file mode 100644 index 7fe5e17d0..000000000 --- a/test-d/foundry/client/apps/placeables/tile-config.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -declare const tile: TileDocument; - -const tileConfig = new TileConfig(tile, { preview: true }); -expectType(tileConfig.document); diff --git a/test-d/foundry/client/apps/placeables/tile-hud.test-d.ts b/test-d/foundry/client/apps/placeables/tile-hud.test-d.ts deleted file mode 100644 index 8670563f6..000000000 --- a/test-d/foundry/client/apps/placeables/tile-hud.test-d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expectType } from "tsd"; - -declare const tile: Tile; - -const hud = new TileHUD(); -expectType(hud.layer); -expectType(hud.object); -hud.bind(tile); -expectType>(hud.getData()); -expectType(hud.setPosition()); diff --git a/test-d/foundry/client/apps/placeables/token-hud.test-d.ts b/test-d/foundry/client/apps/placeables/token-hud.test-d.ts deleted file mode 100644 index 5f0e92453..000000000 --- a/test-d/foundry/client/apps/placeables/token-hud.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -declare const token: Token; - -const hud = new TokenHUD(); -expectType | undefined>(hud.layer); -expectType(hud.object); -hud.bind(token); - -expectType>(hud.getData()); -expectType(hud.setPosition()); diff --git a/test-d/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts b/test-d/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts deleted file mode 100644 index b81073d94..000000000 --- a/test-d/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -declare const message: ChatMessage; - -const popout = new ChatPopout(message); -expectType(popout.message); diff --git a/test-d/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts b/test-d/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts deleted file mode 100644 index 5a37a8d7a..000000000 --- a/test-d/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { expectType } from "tsd"; - -declare const combat: Combat; - -expectType(CombatTracker.defaultOptions); - -const tracker = new CombatTracker(); -expectType[]>(tracker.combats); -expectType(tracker.createPopout()); - -expectType(tracker.initialize()); -tracker.initialize({ combat: null }); -tracker.initialize({ combat: combat }); -tracker.initialize({ render: true }); -tracker.initialize({ render: false }); - -expectType(tracker.scrollToTurn()); -expectType(await tracker.getData()); diff --git a/test-d/foundry/client/apps/sidebar/tabs/settings.test-d.ts b/test-d/foundry/client/apps/sidebar/tabs/settings.test-d.ts deleted file mode 100644 index 7f26496f3..000000000 --- a/test-d/foundry/client/apps/sidebar/tabs/settings.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectType } from "tsd"; - -const frameViewer = new FrameViewer("https://foundryvtt.wiki/", { - title: "My Title", -}); - -expectType(frameViewer.url); diff --git a/test-d/foundry/client/audio/audio.test-d.ts b/test-d/foundry/client/audio/audio.test-d.ts deleted file mode 100644 index 83ed94b62..000000000 --- a/test-d/foundry/client/audio/audio.test-d.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { expectType } from "tsd"; - -const audioHelper = new AudioHelper(); -expectType(audioHelper); -expectType(audioHelper.context); -expectType>( - audioHelper.buffers, -); -expectType>(audioHelper.sounds); -expectType>(audioHelper.playing); -expectType<(() => void)[]>(audioHelper.pending); -expectType(audioHelper.locked); -expectType(AudioHelper.levelAnalyserNativeInterval); -expectType(AudioHelper.registerSettings()); -expectType(audioHelper.create({ src: "a/path/to/some/sound/file.ogg" })); -expectType( - audioHelper.create({ - src: "a/path/to/some/sound/file.ogg", - singleton: false, - preload: true, - autoplay: true, - autoplayOptions: { loop: true, offset: 42, volume: 0.5, fade: 3 }, - }), -); -expectType(AudioHelper.hasAudioExtension("a/path/to/some/sound/file.ogg")); -expectType(AudioHelper.getDefaultSoundName("a/path/to/some/sound/file.ogg")); -expectType>(audioHelper.play("a/path/to/some/sound/file.ogg")); -expectType>( - audioHelper.play("a/path/to/some/sound/file.ogg", { loop: true, offset: 42, volume: 0.5, fade: 3 }), -); -expectType>(audioHelper.awaitFirstGesture()); -expectType>(audioHelper.preload("a/path/to/some/sound/file.ogg")); - -declare const socket: io.Socket; - -expectType(AudioHelper._activateSocketListeners(socket)); -expectType>( - AudioHelper.play({ - src: "a/path/to/some/sound/file.ogg", - }), -); -expectType>( - AudioHelper.play( - { - src: "a/path/to/some/sound/file.ogg", - volume: 0.8, - autoplay: false, - loop: true, - }, - true, - ), -); -expectType>(AudioHelper.preloadSound("a/path/to/some/sound/file.ogg")); -expectType(AudioHelper.inputToVolume(0.5)); -expectType(AudioHelper.inputToVolume("0.5", 1.7)); -expectType(AudioHelper.volumeToInput(0.5)); -expectType(AudioHelper.volumeToInput(0.5, 1.7)); -expectType(audioHelper.getAudioContext()); - -declare const stream: MediaStream; -declare const callback: (maxDecibel: number, fftArray: Float32Array) => void; - -expectType(audioHelper.startLevelReports("some id", stream, callback)); -expectType(audioHelper.startLevelReports("some id", stream, callback, 60, 0.2)); -expectType(audioHelper.stopLevelReports("some id")); diff --git a/test-d/foundry/client/audio/container.test-d.ts b/test-d/foundry/client/audio/container.test-d.ts deleted file mode 100644 index 5bbc5708e..000000000 --- a/test-d/foundry/client/audio/container.test-d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { expectType } from "tsd"; - -const audioContainer = new AudioContainer("a/path/to/some/sound/file.ogg"); -expectType(audioContainer); -expectType(audioContainer.src); -expectType(audioContainer.sourceNode); -expectType(audioContainer.gainNode); -expectType(audioContainer.isBuffer); -expectType(audioContainer.loaded); -expectType(audioContainer.failed); -expectType(audioContainer.playing); -expectType(audioContainer.loop); -expectType(AudioContainer.MAX_BUFFER_DURATION); -expectType(audioContainer.buffer); -expectType(audioContainer.context); -expectType(audioContainer.duration); -expectType(audioContainer.element); -expectType>(audioContainer.load()); -expectType(audioContainer.play(0, () => undefined)); -expectType(audioContainer.stop()); diff --git a/test-d/foundry/client/audio/sound.test-d.ts b/test-d/foundry/client/audio/sound.test-d.ts deleted file mode 100644 index 318a146de..000000000 --- a/test-d/foundry/client/audio/sound.test-d.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { expectType } from "tsd"; - -const sound = new Sound("a/path/to/some/sound/file.ogg"); - -expectType(sound); -expectType(sound.id); -expectType(sound.src); -expectType(sound.container); -expectType(sound.startTime); -expectType(sound.pausedTime); -expectType(sound.events); -expectType | undefined>(sound.loading); -expectType(sound.context); -expectType(sound.node); -expectType(sound.gain); -expectType(sound.currentTime); -expectType(sound.duration); -expectType(sound.loaded); -expectType(sound.failed); -expectType(sound.playing); -expectType(sound.loop); -expectType(sound.volume); -expectType>(sound.fade(0)); -expectType>(sound.fade(0, { duration: 42, from: 0.5, type: "exponential" })); -expectType>(sound.load()); -expectType>( - sound.load({ autoplay: true, autoplayOptions: { loop: true, offset: 2, volume: 0.7, fade: 3 } }), -); -expectType(sound.play()); -expectType(sound.play({ loop: true, offset: 2, volume: 0.7, fade: 3 })); -expectType(sound.pause()); -expectType(sound.stop()); - -declare const soundCallback: (sound: Sound) => void; - -expectType>(sound.schedule(soundCallback, 42)); -expectType(sound.emit("pause")); -expectType(sound.off("end", 42)); -expectType(sound.off("start", soundCallback)); -expectType(sound.on("stop", soundCallback)); diff --git a/test-d/foundry/client/core/hooks.test-d.ts b/test-d/foundry/client/core/hooks.test-d.ts deleted file mode 100644 index cd8c33d18..000000000 --- a/test-d/foundry/client/core/hooks.test-d.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { expectType } from "tsd"; -import "../../../../index"; - -Hooks.on("canvasInit", (canvas) => { - expectType(canvas); -}); -Hooks.on("fooBar", (baz, bar) => { - expectType(baz); - expectType(bar); - return true; -}); -Hooks.on>("closeFormApplication", (app, jq) => { - expectType(app); - expectType(jq); -}); - -Hooks.on("error", (...args) => { - if (args[0] === "Canvas#draw") expectType(args[2].layer); -}); -Hooks.on("error", (...args) => { - if (args[0] === "Game#initializeCanvas") expectType(args[2].foo); -}); -Hooks.on("error", (...args) => { - if (args[0] === "MyClass#myMethod") expectType(args[2].foo); -}); diff --git a/test-d/foundry/client/core/settings.test-d.ts b/test-d/foundry/client/core/settings.test-d.ts deleted file mode 100644 index 8c8d95e1f..000000000 --- a/test-d/foundry/client/core/settings.test-d.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { expectError, expectType } from "tsd"; -import "../../index"; - -const clientSettings = new ClientSettings([]); - -declare global { - // eslint-disable-next-line - namespace ClientSettings { - interface Values { - "foo.bar": boolean; - "some.numberSetting": number; - "some.stringSetting": string; - } - } -} - -expectError( - clientSettings.register("foo", "bar", { - scope: "world", - type: String, - }), -); -expectError(clientSettings.set("foo", "bar", "true")); - -clientSettings.register("foo", "bar", { - scope: "world", - type: Boolean, - config: true, - default: true, -}); -clientSettings.set("foo", "bar", false); -expectType(clientSettings.get("foo", "bar")); - -expectType(clientSettings.get("foo", "baz")); - -// can only use range for number settings -expectError( - clientSettings.register("some", "stringSetting", { - scope: "world", - type: String, - range: { - min: 0, - max: 42, - step: 1, - }, - }), -); - -clientSettings.register("some", "numberSetting", { - scope: "world", - type: Number, - range: { - min: 0, - max: 42, - step: 1, - }, -}); - -// can only use filePicker for string settings -expectError( - clientSettings.register("some", "numberSetting", { - scope: "world", - type: Number, - filePicker: "audio", - }), -); - -clientSettings.register("some", "stringSetting", { - scope: "world", - type: String, - filePicker: "audio", -}); - -// core settings - -expectType<{ resource: string; skipDefeated: boolean } | {}>(clientSettings.get("core", "combatTrackerConfig")); -expectType>>( - clientSettings.get("core", "compendiumConfiguration"), -); -expectType(clientSettings.get("core", "rollMode")); diff --git a/test-d/foundry/client/core/time.test-d.ts b/test-d/foundry/client/core/time.test-d.ts deleted file mode 100644 index d447e0350..000000000 --- a/test-d/foundry/client/core/time.test-d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { expectType } from "tsd"; - -expectType(GameTime.SYNC_INTERVAL_MS); -new GameTime(undefined); -new GameTime(null); - -if (game instanceof Game) { - const time = new GameTime(game.socket); - expectType(time.serverTime); - expectType(time.worldTime); - expectType>(time.advance(100)); - expectType>(time.sync(game.socket)); - expectType>(time.sync(undefined)); - expectType>(time.sync(null)); - expectType(time.onUpdateWorldTime(100)); - expectType(game.settings.get("core", "time")); -} diff --git a/test-d/foundry/client/core/utils.test-d.ts b/test-d/foundry/client/core/utils.test-d.ts deleted file mode 100644 index 031920636..000000000 --- a/test-d/foundry/client/core/utils.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectAssignable } from "tsd"; - -// prove that they are global -expectAssignable(saveDataToFile); -expectAssignable(readTextFromFile); diff --git a/test-d/foundry/client/data/abstract/canvas-document.test-d.ts b/test-d/foundry/client/data/abstract/canvas-document.test-d.ts deleted file mode 100644 index d40349804..000000000 --- a/test-d/foundry/client/data/abstract/canvas-document.test-d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import type * as data from "../../../../../src/foundry/common/data/data.mjs"; - -import { expectAssignable, expectType } from "tsd"; - -const doc = new AmbientLightDocument(); - -// Test the inheritance -expectType<"AmbientLight">(doc.documentName); // Document -expectType(doc.uuid); // clientDocumentMixin -// TODO: change to > | null> once the circular reference problem has been solved -expectType(doc.object); // canvasDocumentMixin -expectType(doc.isGlobal); // class itself - -// Test the inheritance of static members -expectType(AmbientLightDocument.documentName); // Document -expectType(AmbientLightDocument.schema); // Base-Document -expectType>(AmbientLightDocument.createDialog()); // ClientDocumentMixin - -// Test the props -// TODO: change to > | null> once the circular reference problem has been solved -expectAssignable(doc.object); -// TODO: change to > | null> once the circular reference problem has been solved -expectAssignable(doc.layer); -expectType(doc.rendered); diff --git a/test-d/foundry/client/data/abstract/client-document.test-d.ts b/test-d/foundry/client/data/abstract/client-document.test-d.ts deleted file mode 100644 index d7970b0ff..000000000 --- a/test-d/foundry/client/data/abstract/client-document.test-d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import type * as data from "../../../../../src/foundry/common/data/data.mjs"; - -import { expectType } from "tsd"; - -const doc = new Item(); - -// Test the inheritance -expectType<"Item">(doc.documentName); // Document -expectType(doc.migrateSystemData()); // Base-Document -expectType(doc.uuid); // ClientDocumentMixin -expectType(doc.transferredEffects); // class itself - -// Test the inheritance of static members -expectType(Item.documentName); // Document -expectType(Item.schema); // Base-Document -expectType>(Item.createDialog()); // ClientDocumentMixin - -// Properties -// TODO: change to > | null> once the circular reference problem has been solved -expectType(doc.sheet); - -// ensure source can be used to create a new document with createDialog -expectType>(Item.createDialog(doc.toObject())); diff --git a/test-d/foundry/client/data/collections/actors.test-d.ts b/test-d/foundry/client/data/collections/actors.test-d.ts deleted file mode 100644 index 9b973a731..000000000 --- a/test-d/foundry/client/data/collections/actors.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectType } from "tsd"; - -const actors = new Actors(); -expectType>(actors.get("", { strict: true })); -expectType["data"]["_source"][]>(actors.toJSON()); -expectType(actors.directory); -expectType(actors.tokens["foo"]); diff --git a/test-d/foundry/client/data/collections/combats.test-d.ts b/test-d/foundry/client/data/collections/combats.test-d.ts deleted file mode 100644 index 267310ac5..000000000 --- a/test-d/foundry/client/data/collections/combats.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const combatEncounters = new CombatEncounters(); -expectType>(combatEncounters.get("", { strict: true })); -expectType["data"]["_source"][]>(combatEncounters.toJSON()); -expectType(combatEncounters.directory); diff --git a/test-d/foundry/client/data/collections/compendium.test-d.ts b/test-d/foundry/client/data/collections/compendium.test-d.ts deleted file mode 100644 index c838ed643..000000000 --- a/test-d/foundry/client/data/collections/compendium.test-d.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { expectError, expectType } from "tsd"; - -const metadata = { - type: "JournalEntry" as const, - label: "Important Plotholes", - name: "plotholes", - package: "some-package", - path: "path/to/file", - private: false, -}; - -const compendiumCollection = new CompendiumCollection(metadata); -expectType>(compendiumCollection.get("", { strict: true })); -expectType["data"]["_source"]>>(compendiumCollection.toJSON()); - -expectType<{ _id: string } & Partial>( - (await compendiumCollection.getIndex()).get("some id", { strict: true }), -); - -const itemCollection = new CompendiumCollection({ - type: "Item", - label: "Important items", - name: "items", - package: "other-package", - path: "path/to/items", - private: false, -}); -expectType<{ _id: string } & Partial>( - (await itemCollection.getIndex()).get("some id", { strict: true }), -); -expectType<{ _id: string } & Partial>( - (await itemCollection.getIndex({ fields: ["name", "effects", "data"] })).get("some id", { strict: true }), -); - -expectError(await itemCollection.getIndex({ fields: ["nonExistentField"] })); - -expectType[]>(await itemCollection.getDocuments()); // get all items -expectType[]>(await itemCollection.getDocuments({})); // get all items -expectType[]>(await itemCollection.getDocuments({ name: "foo" })); // get all items called "foo" -expectType[]>( - await itemCollection.getDocuments({ $or: [{ name: "baz" }, { name: "bar" }], effects: { $size: 2 } }), // only get items called "baz" or "bar" that have exactly 2 effects -); diff --git a/test-d/foundry/client/data/collections/fog.test-d.ts b/test-d/foundry/client/data/collections/fog.test-d.ts deleted file mode 100644 index 257c7790d..000000000 --- a/test-d/foundry/client/data/collections/fog.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const fogExplorations = new FogExplorations(); -expectType>(fogExplorations.get("", { strict: true })); -expectType["data"]["_source"][]>(fogExplorations.toJSON()); -expectType(fogExplorations.directory); diff --git a/test-d/foundry/client/data/collections/folder.test-d.ts b/test-d/foundry/client/data/collections/folder.test-d.ts deleted file mode 100644 index 0123205f8..000000000 --- a/test-d/foundry/client/data/collections/folder.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const folders = new Folders(); -expectType>(folders.get("", { strict: true })); -expectType["data"]["_source"][]>(folders.toJSON()); -expectType | undefined>(folders.directory); diff --git a/test-d/foundry/client/data/collections/items.test-d.ts b/test-d/foundry/client/data/collections/items.test-d.ts deleted file mode 100644 index 6d936e591..000000000 --- a/test-d/foundry/client/data/collections/items.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const items = new Items(); -expectType>(items.get("", { strict: true })); -expectType["data"]["_source"][]>(items.toJSON()); -expectType(items.directory); diff --git a/test-d/foundry/client/data/collections/journal.test-d.ts b/test-d/foundry/client/data/collections/journal.test-d.ts deleted file mode 100644 index e849f86d6..000000000 --- a/test-d/foundry/client/data/collections/journal.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const journal = new Journal(); -expectType>(journal.get("", { strict: true })); -expectType["data"]["_source"][]>(journal.toJSON()); -expectType(journal.directory); diff --git a/test-d/foundry/client/data/collections/macros.test-d.ts b/test-d/foundry/client/data/collections/macros.test-d.ts deleted file mode 100644 index 41ed3fb77..000000000 --- a/test-d/foundry/client/data/collections/macros.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const macros = new Macros(); -expectType>(macros.get("", { strict: true })); -expectType["data"]["_source"][]>(macros.toJSON()); -expectType(macros.directory); diff --git a/test-d/foundry/client/data/collections/messages.test-d.ts b/test-d/foundry/client/data/collections/messages.test-d.ts deleted file mode 100644 index a2e17bce5..000000000 --- a/test-d/foundry/client/data/collections/messages.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const messages = new Messages(); -expectType>(messages.get("", { strict: true })); -expectType["data"]["_source"][]>(messages.toJSON()); -expectType(messages.directory); diff --git a/test-d/foundry/client/data/collections/playlists.test-d.ts b/test-d/foundry/client/data/collections/playlists.test-d.ts deleted file mode 100644 index cdc4d3ec4..000000000 --- a/test-d/foundry/client/data/collections/playlists.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectType } from "tsd"; -import type { PlaylistDataSource } from "../../../../../src/foundry/common/data/data.mjs/playlistData"; - -const playlists = new Playlists(); -expectType>(playlists.get("", { strict: true })); -expectType<(PlaylistDataSource & { _id: string })[]>(playlists.toJSON()); -expectType(playlists.directory); diff --git a/test-d/foundry/client/data/collections/scenes.test-d.ts b/test-d/foundry/client/data/collections/scenes.test-d.ts deleted file mode 100644 index 555c86139..000000000 --- a/test-d/foundry/client/data/collections/scenes.test-d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { expectType } from "tsd"; - -expectType<"Scene">(Scenes.documentName); - -const scenes = new Scenes(); -expectType | undefined>(scenes.active); -expectType | undefined>(scenes.current); -expectType | undefined>(scenes.viewed); diff --git a/test-d/foundry/client/data/collections/settings.test-d.ts b/test-d/foundry/client/data/collections/settings.test-d.ts deleted file mode 100644 index 3d0fb38e7..000000000 --- a/test-d/foundry/client/data/collections/settings.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectType } from "tsd"; - -const worldSettings = new WorldSettings(); -expectType>(worldSettings.get("", { strict: true })); -expectType | undefined>(worldSettings.getSetting("foo")); -expectType["data"]["_source"][]>(worldSettings.toJSON()); -expectType(worldSettings.directory); diff --git a/test-d/foundry/client/data/collections/tables.test-d.ts b/test-d/foundry/client/data/collections/tables.test-d.ts deleted file mode 100644 index 871371f94..000000000 --- a/test-d/foundry/client/data/collections/tables.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectType } from "tsd"; -import type { RollTableDataSource } from "../../../../../src/foundry/common/data/data.mjs/rollTableData"; - -const rollTables = new RollTables(); -expectType>(rollTables.get("", { strict: true })); -expectType<(RollTableDataSource & { _id: string })[]>(rollTables.toJSON()); -expectType(rollTables.directory); diff --git a/test-d/foundry/client/data/collections/users.test-d.ts b/test-d/foundry/client/data/collections/users.test-d.ts deleted file mode 100644 index a62782302..000000000 --- a/test-d/foundry/client/data/collections/users.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const users = new Users(); -expectType>(users.get("", { strict: true })); -expectType["data"]["_source"][]>(users.toJSON()); -expectType>(users.directory); diff --git a/test-d/foundry/client/data/documents/active-effect.test-d.ts b/test-d/foundry/client/data/documents/active-effect.test-d.ts deleted file mode 100644 index 98092db14..000000000 --- a/test-d/foundry/client/data/documents/active-effect.test-d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { expectError, expectType } from "tsd"; - -const eff = new ActiveEffect({}); - -declare global { - interface FlagConfig { - ActiveEffect: { - mySystem?: { - importantFlag?: boolean; - }; - }; - } -} - -expectType(eff.getFlag("mySystem", "importantFlag")); -expectType(eff.getFlag("core", "statusId")); -expectType(eff.getFlag("core", "overlay")); -expectError(eff.setFlag("core", "statusId", 0)); -expectError(eff.setFlag("core", "overlay", 0)); diff --git a/test-d/foundry/client/data/documents/actor.test-d.ts b/test-d/foundry/client/data/documents/actor.test-d.ts deleted file mode 100644 index 1a32f1d2e..000000000 --- a/test-d/foundry/client/data/documents/actor.test-d.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { expectAssignable, expectType } from "tsd"; - -declare const document: boolean; - -const actor = new Actor({ name: "Beren", type: "npc" }); -expectType(actor.getActiveTokens()); -expectType(actor.getActiveTokens(false, false)); -expectType(actor.getActiveTokens(false, true)); -expectType(actor.getActiveTokens(false, document)); - -expectAssignable(actor.itemTypes["armor"][0].data); - -interface CharacterActor { - data: foundry.data.ActorData & { type: "character"; _source: { type: "character" } }; -} -class CharacterActor extends Actor { - someCustomFunction() { - expectType<"character">(this.data.type); - expectType(this.data.data.movement); - expectType<"character">(this.data._source.type); - expectType(this.data._source.data.health); - } -} - -declare const character: CharacterActor; - -expectType<"character">(character.data.type); -expectType(character.data.data.movement); -expectType<"character">(character.data._source.type); -expectType(character.data._source.data.health); - -expectType<"character">(character.toObject().type); -expectType(character.toObject().data.health); diff --git a/test-d/foundry/client/data/documents/card.test-d.ts b/test-d/foundry/client/data/documents/card.test-d.ts deleted file mode 100644 index ae26ad17a..000000000 --- a/test-d/foundry/client/data/documents/card.test-d.ts +++ /dev/null @@ -1,83 +0,0 @@ -import { expectError, expectType } from "tsd"; - -const card = new Card({ name: "Just a deck of cards" }); -const cards = new Cards({ name: "Some Card Deck", type: "german" }); - -expectType(card.back); -expectType(card.face); -expectType(card.backImg); -expectType(card.img); -expectType(card.name); -expectType(card.source); -expectType(card.isHome); -expectType(card.showFace); -expectType(card.hasNextFace); -expectType(card.hasPreviousFace); - -// flip -expectType>(card.flip()); -expectType>(card.flip(1)); -expectType>(card.flip(null)); -expectType>(card.flip(undefined)); - -// pass -expectType>(card.pass(cards)); -expectType>( - card.pass(cards, { - action: "some custom action", - updateData: { value: 3 }, - chatNotification: true, - }), -); -expectError(card.pass(cards, { unknownProp: 0 })); -expectError(card.pass(cards, { updateData: { unknownProp: 0 } })); - -// play -expectType>(card.play(cards)); -expectType>( - card.play(cards, { - action: "some custom action", - updateData: { value: 3 }, - chatNotification: true, - }), -); -expectError(card.play(cards, { unknownProp: 0 })); -expectError(card.play(cards, { updateData: { unknownProp: 0 } })); - -// discard -expectType>(card.discard(cards)); -expectType>( - card.discard(cards, { - action: "some custom action", - updateData: { value: 3 }, - chatNotification: true, - }), -); -expectError(card.discard(cards, { unknownProp: 0 })); -expectError(card.discard(cards, { updateData: { unknownProp: 0 } })); - -// discard -expectType>(card.reset()); -expectType>( - card.reset({ - updateData: { value: 3 }, - chatNotification: true, - }), -); -expectError(card.reset({ unknownProp: 0 })); -expectError(card.reset({ updateData: { unknownProp: 0 } })); - -// toMessage -expectType>(card.toMessage()); -expectType>( - card.toMessage( - { - speaker: { - alias: "The Speaker", - }, - }, - { - noHook: true, - }, - ), -); diff --git a/test-d/foundry/client/data/documents/cards.test-d.ts b/test-d/foundry/client/data/documents/cards.test-d.ts deleted file mode 100644 index 9724d5b2c..000000000 --- a/test-d/foundry/client/data/documents/cards.test-d.ts +++ /dev/null @@ -1,103 +0,0 @@ -import { expectError, expectType } from "tsd"; - -const cards = new Cards({ name: "Just a deck of cards", type: "german" }); - -expectType(cards.thumbnail); -expectType(cards.availableCards); -expectType(cards.drawnCards); - -// deal -expectType>(cards.deal([cards])); -expectType>(cards.deal([cards], 2)); -expectType>( - cards.deal([cards], 2, { - how: foundry.CONST.CARD_DRAW_MODES.RANDOM, - action: "some custom action", - updateData: { value: 3 }, - chatNotification: true, - }), -); -expectType>( - cards.deal([cards], undefined, { - how: foundry.CONST.CARD_DRAW_MODES.RANDOM, - action: "some custom action", - updateData: { value: 3 }, - chatNotification: true, - }), -); -expectError(cards.deal([cards], undefined, { unknownProp: 0 })); -expectError(cards.deal([cards], undefined, { updateData: { unknownProp: 3 } })); - -// pass -expectError(cards.pass(cards)); -expectType>(cards.pass(cards, ["foo"])); -expectType>( - cards.pass(cards, ["foo"], { - action: "some custom action", - updateData: { value: 3 }, - chatNotification: true, - }), -); -expectError(cards.pass(cards, ["foo"], { unknownProp: 0 })); -expectError(cards.pass(cards, ["foo"], { updateData: { unknownProp: 0 } })); - -// draw -expectType>(cards.draw(cards)); -expectType>(cards.draw(cards, 2)); -expectType>( - cards.draw(cards, 2, { - how: foundry.CONST.CARD_DRAW_MODES.RANDOM, - action: "some custom action", - updateData: { value: 3 }, - }), -); -expectType>( - cards.draw(cards, undefined, { - how: foundry.CONST.CARD_DRAW_MODES.RANDOM, - action: "some custom action", - updateData: { value: 3 }, - }), -); -expectError(cards.draw(cards, undefined, { unknownProp: 0 })); -expectError(cards.draw(cards, undefined, { updateData: { unknownProp: 3 } })); - -// shuffle -expectType>(cards.shuffle()); -expectType>( - cards.shuffle({ - updateData: { - value: 1, - }, - chatNotification: true, - }), -); -expectError(cards.shuffle({ unknownProp: 0 })); -expectError(cards.shuffle({ updateData: { unknownProp: 3 } })); - -// reset -expectType>(cards.reset()); -expectType>( - cards.reset({ - updateData: { - value: 1, - }, - chatNotification: true, - }), -); -expectError(cards.reset({ unknownProp: 0 })); -expectError(cards.reset({ updateData: { unknownProp: 3 } })); - -// dealDialog -expectType>(cards.dealDialog()); - -// drawDialog -expectType>(cards.drawDialog()); - -// passDialog -expectType>(cards.passDialog()); - -// playDialog -expectType>(cards.playDialog(new Card({ name: "Some Card" }))); - -// resetDialog -expectType>(cards.resetDialog()); diff --git a/test-d/foundry/client/data/documents/chat-message.test-d.ts b/test-d/foundry/client/data/documents/chat-message.test-d.ts deleted file mode 100644 index 72c4ab9ec..000000000 --- a/test-d/foundry/client/data/documents/chat-message.test-d.ts +++ /dev/null @@ -1,82 +0,0 @@ -import type { ChatSpeakerData } from "../../../../../src/foundry/common/data/data.mjs/chatSpeakerData"; -import type { ConstructorDataType } from "../../../../../src/types/helperTypes"; - -import { expectError, expectType } from "tsd"; - -expectType(new ChatMessage()); -expectType(new ChatMessage({})); - -expectType>( - ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.BLIND), -); -expectType>( - ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.PRIVATE), -); -expectType>( - ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.PUBLIC), -); -expectType>( - ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.SELF), -); - -expectType>( - ChatMessage.applyRollMode(new foundry.data.ChatMessageData(), "roll"), -); - -declare global { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace CONFIG { - // eslint-disable-next-line @typescript-eslint/no-namespace - namespace Dice { - interface RollModes { - "custom-roll-mode": "Some Custom Roll Mode"; - } - } - } -} - -expectType>( - ChatMessage.applyRollMode(new foundry.data.ChatMessageData(), "custom-roll-mode"), -); - -expectError(ChatMessage.applyRollMode(new foundry.data.ChatMessageData(), "unknown-roll-mode")); - -expectType(ChatMessage.getSpeaker()); -expectType(ChatMessage.getSpeaker({})); -if (game instanceof Game) { - expectType(ChatMessage.getSpeaker({ scene: game.scenes?.active })); - expectType(ChatMessage.getSpeaker({ actor: game.user?.character })); - expectType( - ChatMessage.getSpeaker({ - scene: game.scenes?.active, - actor: game.user?.character, - token: new TokenDocument(), - alias: "Mario", - }), - ); -} -expectType(ChatMessage.getSpeaker({ token: new TokenDocument() })); -expectType(ChatMessage.getSpeaker({ alias: "Mario" })); - -expectType(ChatMessage.getSpeakerActor(ChatMessage.getSpeaker())); -expectType[]>(ChatMessage.getWhisperRecipients("Mario")); - -const chat = new ChatMessage(); -expectType(chat.alias); -expectType(chat.isAuthor); -expectType(chat.isContentVisible); -expectType(chat.isRoll); -expectType(chat.roll); -expectType(chat.visible); -expectType(chat.user); -expectType(chat.prepareData()); -expectType(chat.applyRollMode(CONST.DICE_ROLL_MODES.BLIND)); -expectType(chat.applyRollMode(CONST.DICE_ROLL_MODES.PRIVATE)); -expectType(chat.applyRollMode(CONST.DICE_ROLL_MODES.PUBLIC)); -expectType(chat.applyRollMode(CONST.DICE_ROLL_MODES.SELF)); -expectType(chat.applyRollMode("roll")); -expectType(chat.applyRollMode("custom-roll-mode")); -expectError(chat.applyRollMode("unknown-roll-mode")); -expectType(chat.getRollData()); -expectType>(chat.getHTML()); -expectType(chat.export()); diff --git a/test-d/foundry/client/data/documents/combatant.test-d.ts b/test-d/foundry/client/data/documents/combatant.test-d.ts deleted file mode 100644 index 7502bc5e0..000000000 --- a/test-d/foundry/client/data/documents/combatant.test-d.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { expectType } from "tsd"; - -const combatant = new Combatant({}, {}); - -// static properties of `BaseCombatant` -expectType(Combatant.schema); - -// properties -expectType(combatant.pack); -expectType(combatant.parent); -expectType(combatant.combat); -expectType(combatant.actor); -expectType(combatant.token); -expectType>(combatant.apps); - -// static properties -expectType | undefined>>(Combatant.create({ name: "Some Combatant" })); -expectType[]>>(Combatant.createDocuments([])); -expectType>(Combatant.updateDocuments([])); -expectType>(Combatant.deleteDocuments([])); diff --git a/test-d/foundry/client/data/documents/drawing.test-d.ts b/test-d/foundry/client/data/documents/drawing.test-d.ts deleted file mode 100644 index 596931f89..000000000 --- a/test-d/foundry/client/data/documents/drawing.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectType } from "tsd"; - -const doc = new DrawingDocument(); - -expectType(doc.author); diff --git a/test-d/foundry/client/data/documents/fog-exploration.test-d.ts b/test-d/foundry/client/data/documents/fog-exploration.test-d.ts deleted file mode 100644 index 230d4112f..000000000 --- a/test-d/foundry/client/data/documents/fog-exploration.test-d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { expectType } from "tsd"; - -declare const pointSource: PointSource; -declare const scene: Scene; -declare const user: User; - -expectType | null>>(FogExploration.get()); -expectType | null>>(FogExploration.get({})); -expectType | null>>(FogExploration.get({ user })); -expectType | null>>(FogExploration.get({ scene })); -expectType | null>>(FogExploration.get({ scene, user })); -expectType | null>>(FogExploration.get({}, { temporary: true })); - -const fogExploration = new FogExploration(); - -expectType(fogExploration.explore(pointSource)); -expectType(fogExploration.explore(pointSource, true)); - -expectType(fogExploration.getTexture()); diff --git a/test-d/foundry/client/data/documents/folder.test-d.ts b/test-d/foundry/client/data/documents/folder.test-d.ts deleted file mode 100644 index ebed03e4c..000000000 --- a/test-d/foundry/client/data/documents/folder.test-d.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { expectType } from "tsd"; - -expectType(await Folder.createDialog()); diff --git a/test-d/foundry/client/data/documents/macro.test-d.ts b/test-d/foundry/client/data/documents/macro.test-d.ts deleted file mode 100644 index 3ae3e0cba..000000000 --- a/test-d/foundry/client/data/documents/macro.test-d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { expectType } from "tsd"; -import "../../../index"; - -const macro = new Macro({ name: "my macro", scope: "global", type: "script" }); - -// properties and functions added by the concrete `Macro` class -expectType(macro.isAuthor); -expectType<(scope?: { actor?: Actor; token?: Token }) => void>(macro.execute); - -// properties and functions of `ClientDocumentMixin` -expectType>(macro.apps); -expectType>(macro.collection); -expectType(macro.folder); -expectType(macro.isOwner); - -// static properties and functions of `ClientDocumentMixin` -expectType>(Macro.createDialog()); - -// static properties of `BaseMacro` -expectType(Macro.schema); - -// properties of `Document` -expectType(macro.parent); -expectType(macro.pack); - -// static properties of `Document` -expectType | undefined>>(Macro.create({ name: "Some Macro" })); -expectType[]>>(Macro.createDocuments([])); -expectType>(Macro.updateDocuments([])); -expectType>(Macro.deleteDocuments([])); diff --git a/test-d/foundry/client/data/documents/measured-template.test-d.ts b/test-d/foundry/client/data/documents/measured-template.test-d.ts deleted file mode 100644 index 3278f8cbd..000000000 --- a/test-d/foundry/client/data/documents/measured-template.test-d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expectType } from "tsd"; - -const doc = new MeasuredTemplateDocument(); - -expectType(doc.author); -// TODO: Modify to TemplateLayer | null once data can be grabbed from CONFIG -expectType>(doc.layer); - -// TODO: Modify to MeasuredTemplateConfig | null once data can be grabbed from CONFIG -expectType(doc.sheet); diff --git a/test-d/foundry/client/data/documents/note.test-d.ts b/test-d/foundry/client/data/documents/note.test-d.ts deleted file mode 100644 index c7c73d7c0..000000000 --- a/test-d/foundry/client/data/documents/note.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const doc = new NoteDocument(); - -expectType(doc.label); -expectType | undefined>(doc.entry); diff --git a/test-d/foundry/client/data/documents/scene.test-d.ts b/test-d/foundry/client/data/documents/scene.test-d.ts deleted file mode 100644 index eb75c5add..000000000 --- a/test-d/foundry/client/data/documents/scene.test-d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new Scene()); -expectError(new Scene({})); - -const scene = new Scene({ name: "My scene" }); -expectType(scene); - -expectType>(scene.dimensions); -expectType(scene.active); -expectType(scene.img); -expectType(scene.isView); -expectType(scene.journal); -expectType(scene.playlist); -expectType(scene.playlistSound); -expectType>(scene.activate()); -expectType>(scene.view()); -expectType>(scene.clone()); -expectType(scene.prepareBaseData()); -expectType>(scene.createThumbnail()); -expectType>(scene.createThumbnail({})); -expectType>(scene.createThumbnail({ img: "path/to/my/img.png" })); -expectType>(scene.createThumbnail({ width: 300 })); -expectType>(scene.createThumbnail({ height: 100 })); diff --git a/test-d/foundry/client/data/documents/setting.test-d.ts b/test-d/foundry/client/data/documents/setting.test-d.ts deleted file mode 100644 index 41780f80e..000000000 --- a/test-d/foundry/client/data/documents/setting.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -const setting = new Setting({ key: "foo.bar", value: "bar" }); - -expectType(Setting.schema); -expectType(setting.key); -expectType(setting.value); -expectType | undefined>>(Setting.create({ key: "foo.bar", value: "bar" })); -expectType[]>>(Setting.createDocuments([])); -expectType>(Setting.updateDocuments([])); -expectType>(Setting.deleteDocuments([])); diff --git a/test-d/foundry/client/data/documents/table.test-d.ts b/test-d/foundry/client/data/documents/table.test-d.ts deleted file mode 100644 index 7cbde374c..000000000 --- a/test-d/foundry/client/data/documents/table.test-d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expectError, expectType } from "tsd"; - -const table = new RollTable({ name: "" }); - -expectError(new RollTable({})); - -expectType(table.results.get("testing")); - -expectType(await table.draw()); -expectType((await table.roll()).results[0]); -expectType(table.data.displayRoll); - -declare const folder: Folder; -expectType(await RollTable.fromFolder(folder)); diff --git a/test-d/foundry/client/data/documents/tile.test-d.ts b/test-d/foundry/client/data/documents/tile.test-d.ts deleted file mode 100644 index 2b6db69ea..000000000 --- a/test-d/foundry/client/data/documents/tile.test-d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { expectType } from "tsd"; - -const doc = new TileDocument(); -expectType(doc.layer); diff --git a/test-d/foundry/client/data/documents/token.test-d.ts b/test-d/foundry/client/data/documents/token.test-d.ts deleted file mode 100644 index 4e9204e40..000000000 --- a/test-d/foundry/client/data/documents/token.test-d.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type EmbeddedCollection from "../../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; -import type { ConfiguredDocumentClass } from "../../../../../src/types/helperTypes"; - -import { expectType } from "tsd"; - -const doc = new TokenDocument({}, { parent: new foundry.documents.BaseScene() }); -expectType> | null>(doc.actor); -expectType(doc.isOwner); -expectType(doc.isLinked); -expectType> | null>(doc.combatant); -expectType(doc.inCombat); -expectType(doc.clone()); -expectType(doc.clone({}, { save: true })); -expectType> | null>(doc.getActor()); -expectType> | null]>>( - doc.modifyActorDocument({ actorLink: true, "lightAnimation.speed": 5 }, {}), -); - -expectType, foundry.data.ActorData>>( - doc.getEmbeddedCollection("Item"), -); -expectType< - EmbeddedCollection, foundry.data.ActorData> ->(doc.getEmbeddedCollection("ActiveEffect")); - -expectType>>>>( - doc.createActorEmbeddedDocuments("Item", [{ name: "My Item", "effects.": 5 }], { noHook: true }), -); -expectType>>>>( - doc.createActorEmbeddedDocuments("ActiveEffect", [{ icon: "path/to/my/icon", "flags.my-system.something": "6" }], {}), -); - -expectType>>>>( - doc.updateActorEmbeddedDocuments("Item", [{ name: "My Item", "data.something": 5 }], { noHook: true }), -); -expectType>>>>( - doc.updateActorEmbeddedDocuments("ActiveEffect", [{ icon: "path/to/my/icon", "flags.my-system.something": "6" }], {}), -); - -expectType>>>>( - doc.deleteActorEmbeddedDocuments("Item", ["BRBEA"], {}), -); -expectType>>>>( - doc.deleteActorEmbeddedDocuments("ActiveEffect", ["BRBEA"], { noHook: true }), -); diff --git a/test-d/foundry/client/data/documents/user.test-d.ts b/test-d/foundry/client/data/documents/user.test-d.ts deleted file mode 100644 index dd60703d8..000000000 --- a/test-d/foundry/client/data/documents/user.test-d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import type { ConfiguredDocumentClass } from "../../../../../src/types/helperTypes"; - -import { expectAssignable, expectType } from "tsd"; - -const user = new User({ name: "Test" }); - -expectType(user.active); -expectType(user.targets); -expectType(user.id); -expectType(user.viewedScene); -expectType(user.avatar); -expectType>> | undefined>(user.character); -expectType | undefined>(user.character); -expectAssignable>>(user.permissions); -expectType>(user.getHotbarMacros().map((each) => each.macro)); -expectType> | null>>( - user.getHotbarMacros().map((each) => each.macro), -); - -user.assignHotbarMacro(new Macro(), 1); - -expectType(user.data._id); -expectType(user.data.character); -expectType(user.data.avatar); - -// TODO: Modify to ConfiguredDocumentSheet | null once data can be grabbed from CONFIG -expectType(user.sheet); - -expectType(user.charname); -expectType(user.color); -expectType(user.border); diff --git a/test-d/foundry/client/data/documents/wall.test-d.ts b/test-d/foundry/client/data/documents/wall.test-d.ts deleted file mode 100644 index 5f90f4886..000000000 --- a/test-d/foundry/client/data/documents/wall.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectError } from "tsd"; - -declare const scene: Scene; - -expectError(new WallDocument()); -expectError(new WallDocument({})); - -new WallDocument({ c: [0, 0, 0, 0] }); -new WallDocument({ c: [0, 0, 0, 0] }, { parent: scene }); diff --git a/test-d/foundry/client/dice/roll.test-d.ts b/test-d/foundry/client/dice/roll.test-d.ts deleted file mode 100644 index 26d6de629..000000000 --- a/test-d/foundry/client/dice/roll.test-d.ts +++ /dev/null @@ -1,82 +0,0 @@ -import type { Evaluated, MessageData } from "../../../../src/foundry/client/dice/roll"; - -import { expectType } from "tsd"; -import "../../index"; - -class CustomRoll extends Roll {} - -CONFIG.Dice.rolls = [CustomRoll, Roll]; - -// Attack with advantage! -const r = new Roll("2d20kh + @prof + @strMod", { prof: 2, strMod: 4 }); - -// create the configured roll instance -expectType>(Roll.create("1d20")); -expectType>(Roll.create("1d20 + @prof", { prof: 2 })); -expectType>(Roll.fromTerms([])); -expectType>(CustomRoll.fromTerms([])); - -// The parsed terms of the roll formula -// [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] -expectType(r.terms); - -// Execute the roll -type TypeOfR = Roll<{ prof: number; strMod: number }>; -expectType>>(r.evaluate({ async: true })); -expectType>(r.evaluate({ async: false })); -expectType>>(r.evaluate()); -expectType>(r.evaluate({ minimize: true, maximize: true })); -expectType | Promise>>( - r.evaluate({ minimize: true, maximize: true, async: false as boolean }), -); -expectType | Promise>>( - r.evaluate({ minimize: true, maximize: true, async: false as boolean | undefined }), -); -expectType>(r.evaluate({ minimize: true, maximize: true, async: false as false | undefined })); -expectType | Promise>>( - r.evaluate({ minimize: true, maximize: true, async: false as true | undefined }), -); -expectType((await r.evaluate()).total); - -expectType>>(r.roll({ async: true })); -expectType>(r.roll({ async: false })); -expectType>>(r.roll()); -expectType>(r.roll({ minimize: true, maximize: true })); -expectType | Promise>>( - r.roll({ minimize: true, maximize: true, async: false as boolean }), -); -expectType | Promise>>( - r.roll({ minimize: true, maximize: true, async: false as boolean | undefined }), -); -expectType>(r.roll({ minimize: true, maximize: true, async: false as false | undefined })); -expectType | Promise>>( - r.roll({ minimize: true, maximize: true, async: false as true | undefined }), -); -expectType((await r.roll()).total); - -expectType>>(r.reroll({ async: true })); -expectType>(r.reroll({ async: false })); -expectType>>(r.reroll()); -expectType>(r.reroll({ minimize: true, maximize: true })); -expectType | Promise>>( - r.reroll({ minimize: true, maximize: true, async: false as boolean }), -); -expectType | Promise>>( - r.reroll({ minimize: true, maximize: true, async: false as boolean | undefined }), -); -expectType>(r.reroll({ minimize: true, maximize: true, async: false as false | undefined })); -expectType | Promise>>( - r.reroll({ minimize: true, maximize: true, async: false as true | undefined }), -); -expectType((await r.reroll()).total); - -// The resulting equation after it was rolled -expectType(r.result); // 16 + 2 + 4 - -// The total resulting from the roll -expectType(r.total); // 22 - -expectType>(r.toMessage()); -expectType>(r.toMessage({}, { create: true })); -expectType>(r.toMessage({}, { create: false })); -expectType | MessageData<{}>>(r.toMessage({}, { create: false as boolean })); diff --git a/test-d/foundry/client/dice/term.test-d.ts b/test-d/foundry/client/dice/term.test-d.ts deleted file mode 100644 index 28b1bee73..000000000 --- a/test-d/foundry/client/dice/term.test-d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { expectType } from "tsd"; -import "../../index"; - -class CustomRollTerm extends RollTerm { - someProperty = 42; -} - -const r = new CustomRollTerm(); - -expectType>(r.evaluate({ async: true })); -expectType(r.evaluate({ async: false })); -expectType(r.evaluate()); -expectType(r.evaluate({ minimize: true, maximize: true })); -expectType>( - r.evaluate({ minimize: true, maximize: true, async: false as boolean }), -); -expectType>( - r.evaluate({ minimize: true, maximize: true, async: false as boolean | undefined }), -); -expectType(r.evaluate({ minimize: true, maximize: true, async: false as false | undefined })); -expectType>( - r.evaluate({ minimize: true, maximize: true, async: false as true | undefined }), -); diff --git a/test-d/foundry/client/game.test-d.ts b/test-d/foundry/client/game.test-d.ts deleted file mode 100644 index d1cf7702d..000000000 --- a/test-d/foundry/client/game.test-d.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { expectAssignable, expectError, expectType } from "tsd"; - -declare const aGame: Game; - -expectType(aGame.combats); -expectType(aGame.i18n); -expectType(aGame.settings); - -declare global { - interface ModuleConfig { - "optional-api-module": { - api: { - testApi: (value: string) => boolean; - }; - }; - "api-module-with-optional-props": { - always: string; - maybe?: number; - }; - "required-api-module": { - hooks: { - triggerDialog: (value: number) => void; - }; - }; - } - interface RequiredModules { - "required-module": true; - "required-api-module": true; - } -} -/** Convenance type for test, might be worth while moving inside the types */ -type Module = Game.ModuleData; - -expectAssignable(aGame.modules.get("optional-module")); - -expectType(aGame.modules.get("required-module")); - -const optionalApiModule = aGame.modules.get("optional-api-module"); -if (optionalApiModule) { - expectType(optionalApiModule.api); - if (optionalApiModule.active) { - expectType(optionalApiModule.active); - expectType<(value: string) => boolean>(optionalApiModule.api.testApi); - } else { - expectType(optionalApiModule.active); - expectType(optionalApiModule.api); - } -} - -const moduleOptionalProps = aGame.modules.get("api-module-with-optional-props"); -if (moduleOptionalProps) { - expectType(moduleOptionalProps.always); - expectType(moduleOptionalProps.maybe); - if (moduleOptionalProps.active) { - expectType(moduleOptionalProps.always); - expectType(moduleOptionalProps.maybe); - expectError(moduleOptionalProps.maybe); - } -} -const requiredApiModule = aGame.modules.get("required-api-module"); - -expectType(requiredApiModule); -expectType(requiredApiModule.hooks.triggerDialog(5)); diff --git a/test-d/foundry/client/head.test-d.ts b/test-d/foundry/client/head.test-d.ts deleted file mode 100644 index 63f33c882..000000000 --- a/test-d/foundry/client/head.test-d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { expectType } from "tsd"; - -expectType(game); -expectType(ui.menu); diff --git a/test-d/foundry/client/pixi/board.test-d.ts b/test-d/foundry/client/pixi/board.test-d.ts deleted file mode 100644 index f61af2e05..000000000 --- a/test-d/foundry/client/pixi/board.test-d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { expectAssignable, expectType } from "tsd"; - -type TilesLayer = unknown; // FIXME: remove when TilesLayer is typed - -const myCanvas = new Canvas(); -expectAssignable>>>(Canvas.layers); -expectType>(myCanvas.draw(new Scene({ name: "My Scene" }))); - -expectType(myCanvas.getLayerByEmbeddedName("AmbientLight")); -expectType(myCanvas.getLayerByEmbeddedName("AmbientSound")); -expectType(myCanvas.getLayerByEmbeddedName("Drawing")); -expectType(myCanvas.getLayerByEmbeddedName("Note")); -expectType(myCanvas.getLayerByEmbeddedName("MeasuredTemplate")); -expectType(myCanvas.getLayerByEmbeddedName("Tile")); -expectType(myCanvas.getLayerByEmbeddedName("Token")); -expectType(myCanvas.getLayerByEmbeddedName("Wall")); -expectType(myCanvas.getLayerByEmbeddedName("any-string")); - -expectType>(myCanvas.animatePan()); -expectType>(myCanvas.animatePan({})); -expectType>(myCanvas.animatePan({ x: 100, y: 100, scale: 1, duration: 250, speed: 10 })); - -expectType>(myCanvas.recenter()); -expectType>(myCanvas.recenter({})); -expectType>(myCanvas.recenter({ x: null, y: null, scale: null })); -expectType>(myCanvas.recenter({ x: 100, y: 100, scale: 1 })); - -expectType( - myCanvas.addPendingOperation("Canvas.recenter", myCanvas.recenter, myCanvas, { x: 100, y: 100, scale: 1 }), -); diff --git a/test-d/foundry/client/pixi/core/containers/cached-container.test-d.ts b/test-d/foundry/client/pixi/core/containers/cached-container.test-d.ts deleted file mode 100644 index 26b14bde8..000000000 --- a/test-d/foundry/client/pixi/core/containers/cached-container.test-d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { expectAssignable, expectType } from "tsd"; - -const container = new CachedContainer(); -expectAssignable(container); -expectType(container.renderTexture); -expectType<[number, number, number, number]>(container.clearColor); -expectType(container.displayed); -expectType(container.destroy()); -expectType( - container.destroy({ - children: false, - texture: false, - baseTexture: false, - }), -); -expectType(container.render(new PIXI.Renderer())); diff --git a/test-d/foundry/client/pixi/core/interaction/targets.test-d.ts b/test-d/foundry/client/pixi/core/interaction/targets.test-d.ts deleted file mode 100644 index b0fa726a9..000000000 --- a/test-d/foundry/client/pixi/core/interaction/targets.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -declare const user: User; -declare const token: Token; - -const targets = new UserTargets(user); -expectType(targets.user); -expectType(targets.ids); -expectType(targets.add(token)); -expectType(targets.clear()); -expectType(targets.delete(token)); diff --git a/test-d/foundry/client/pixi/core/loader.test-d.ts b/test-d/foundry/client/pixi/core/loader.test-d.ts deleted file mode 100644 index 567603cbd..000000000 --- a/test-d/foundry/client/pixi/core/loader.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; - -expectType>(srcExists("path/to/texture")); - -expectType(getTexture("path/to/texture")); - -expectType>(loadTexture("path/to/texture")); -expectType>(loadTexture("path/to/texture", {})); -expectType>(loadTexture("path/to/texture", { fallback: "path/to/another/texture" })); diff --git a/test-d/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts b/test-d/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts deleted file mode 100644 index 1a90acdf8..000000000 --- a/test-d/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectAssignable, expectType } from "tsd"; - -const rectangle = new NormalizedRectangle(100, 300, 500, 400); -expectAssignable(rectangle); -expectType(rectangle.rotate(0.5)); - -expectType(NormalizedRectangle.fromRotation(100, 300, 200, 100, 0.5)); diff --git a/test-d/foundry/client/pixi/layers/controls/cursor.test-d.ts b/test-d/foundry/client/pixi/layers/controls/cursor.test-d.ts deleted file mode 100644 index 6a037ea91..000000000 --- a/test-d/foundry/client/pixi/layers/controls/cursor.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; - -declare const user: User; - -const cursor = new Cursor(user); -expectType(cursor.draw(user)); -expectType(cursor.destroy()); -expectType(cursor.destroy({})); -expectType(cursor.destroy({ children: true, texture: true, baseTexture: true })); diff --git a/test-d/foundry/client/pixi/layers/controls/door.test-d.ts b/test-d/foundry/client/pixi/layers/controls/door.test-d.ts deleted file mode 100644 index 2be7407b7..000000000 --- a/test-d/foundry/client/pixi/layers/controls/door.test-d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expectError, expectType } from "tsd"; - -declare const wall: Wall; - -expectError(new DoorControl()); - -const control = new DoorControl(wall); -expectType(control.wall); -expectType>(control.draw()); -expectType(control.bg); -expectType(control.icon); -expectType(control.border); -expectType(control.reposition()); -expectType(control.isVisible); diff --git a/test-d/foundry/client/pixi/layers/controls/ruler.test-d.ts b/test-d/foundry/client/pixi/layers/controls/ruler.test-d.ts deleted file mode 100644 index 65dbdcc0d..000000000 --- a/test-d/foundry/client/pixi/layers/controls/ruler.test-d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { expectType } from "tsd"; - -if (game instanceof Game) { - expectType(new Ruler(undefined)); - expectType(new Ruler(game.user, { color: null })); - expectType(new Ruler(game.user, { color: 0x32f4e2 })); -} - -const ruler = new Ruler(); -expectType(ruler.user); -expectType(ruler.name); -expectType(ruler.color); -expectType(ruler.waypoints); -expectType(ruler.destination); -expectType(ruler.ruler); -expectType(ruler.labels); -expectType<{ INACTIVE: 0; STARTING: 1; MEASURING: 2; MOVING: 3 }>(Ruler.STATES); -expectType(ruler.active); - -expectType>(ruler.measure(new PIXI.Point())); -expectType>(ruler.measure({ x: 10, y: 10 }, {})); -expectType>(ruler.measure({ x: 10, y: 10 }, { gridSpaces: true })); - -expectType>(ruler.moveToken()); -expectType(ruler.clear()); -expectType(ruler.toJSON()); -expectType(ruler.update(ruler.toJSON())); diff --git a/test-d/foundry/client/pixi/layers/drawings.test-d.ts b/test-d/foundry/client/pixi/layers/drawings.test-d.ts deleted file mode 100644 index e07e98e20..000000000 --- a/test-d/foundry/client/pixi/layers/drawings.test-d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { expectType } from "tsd"; - -expectType<"Drawing">(DrawingsLayer.documentName); -expectType(DrawingsLayer.instance); -expectType(DrawingsLayer.layerOptions); -expectType<"drawings">(DrawingsLayer.layerOptions.name); -expectType(DrawingsLayer.layerOptions.objectClass); -expectType<"defaultDrawingConfig">(DrawingsLayer.DEFAULT_CONFIG_SETTING); - -const layer = new DrawingsLayer(); -expectType(layer.options.objectClass); -expectType(layer.options); -expectType<"drawings">(layer.options.name); -expectType<16 | 8 | 0>(layer.gridPrecision); -expectType(layer.hud); -expectType(layer.configureDefault()); -expectType(layer.deactivate()); diff --git a/test-d/foundry/client/pixi/layers/effects.test-d.ts b/test-d/foundry/client/pixi/layers/effects.test-d.ts deleted file mode 100644 index 7ff9091d7..000000000 --- a/test-d/foundry/client/pixi/layers/effects.test-d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { expectType } from "tsd"; - -expectType(WeatherLayer.instance); -expectType(WeatherLayer.layerOptions); -expectType<"effects">(WeatherLayer.layerOptions.name); - -const layer = new WeatherLayer(); -expectType<"effects">(layer.options.name); -expectType(layer.weather); -expectType(layer.weatherEffect); -expectType(layer.emitters); -expectType(layer.weatherOcclusionFilter); -expectType>(layer.tearDown()); -expectType>(layer.draw()); -expectType(layer.drawWeather()); diff --git a/test-d/foundry/client/pixi/layers/grid.test-d.ts b/test-d/foundry/client/pixi/layers/grid.test-d.ts deleted file mode 100644 index 1685674bc..000000000 --- a/test-d/foundry/client/pixi/layers/grid.test-d.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { expectType } from "tsd"; - -expectType(GridLayer.instance); -expectType(GridLayer.layerOptions); -expectType<"grid">(GridLayer.layerOptions.name); - -const layer = new GridLayer(); -expectType<"grid">(layer.options.name); -expectType(layer.grid); -expectType(layer.highlight); -expectType>(layer.highlightLayers); -expectType(layer.type); -expectType(layer.size); -expectType(layer.w); -expectType(layer.h); -expectType(layer.isHex); -expectType>(layer.draw()); -expectType>(layer.draw({})); -expectType>(layer.draw({ type: null, dimensions: null, gridColor: null, gridAlpha: null })); -expectType>(layer.draw({ type: foundry.CONST.GRID_TYPES.GRIDLESS })); -expectType>(layer.draw({ dimensions: (canvas as Canvas).dimensions })); -expectType>(layer.draw({ gridColor: "#000000" })); -expectType>(layer.draw({ gridColor: 0x000000 })); -expectType>(layer.draw({ gridAlpha: 0.2 })); -expectType<{ x: number; y: number }>(layer.getSnappedPosition(10, 100)); -expectType<{ x: number; y: number }>(layer.getSnappedPosition(10, 100, 2)); -expectType<[number, number]>(layer.getTopLeft(8, 17)); -expectType<[number, number]>(layer.getCenter(8, 17)); -expectType(layer.measureDistance({ x: 8, y: 17 }, { x: 1100, y: 1200 })); -expectType(layer.measureDistances([{ ray: new Ray({ x: 8, y: 17 }, { x: 1100, y: 1200 }) }])); -expectType(layer.measureDistances([{ ray: new Ray({ x: 8, y: 17 }, { x: 1100, y: 1200 }) }], {})); -expectType( - layer.measureDistances([{ ray: new Ray({ x: 8, y: 17 }, { x: 1100, y: 1200 }) }], { gridSpaces: true }), -); -expectType(layer.addHighlightLayer("some")); -expectType(layer.getHighlightLayer("some")); -expectType(layer.clearHighlightLayer("some")); -expectType(layer.destroyHighlightLayer("some")); -expectType(layer.highlightPosition("some")); -expectType( - layer.highlightPosition("some", { - x: 10, - y: 100, - color: 0x33bbff, - border: null, - alpha: 0.25, - shape: new PIXI.Polygon(), - }), -); -expectType(layer.isNeighbor(0, 1, 2, 3)); diff --git a/test-d/foundry/client/pixi/layers/grid/highlight.test-d.ts b/test-d/foundry/client/pixi/layers/grid/highlight.test-d.ts deleted file mode 100644 index 6e87e16ab..000000000 --- a/test-d/foundry/client/pixi/layers/grid/highlight.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -expectType(new GridHighlight("")); - -const grid = new GridHighlight("", new PIXI.GraphicsGeometry()); -expectType(grid.name); -expectType>(grid.positions); -expectType(grid.highlight(100, 100)); -expectType(grid.clear()); -expectType(grid.destroy()); -expectType(grid.destroy({ children: true, texture: true, baseTexture: true })); diff --git a/test-d/foundry/client/pixi/layers/lighting.test-d.ts b/test-d/foundry/client/pixi/layers/lighting.test-d.ts deleted file mode 100644 index bd2818cdd..000000000 --- a/test-d/foundry/client/pixi/layers/lighting.test-d.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { expectType } from "tsd"; - -expectType(LightingLayer.instance); -expectType(LightingLayer.layerOptions.objectClass); - -const layer = new LightingLayer(); -expectType(layer.options.objectClass); -expectType(layer.options); -expectType<"lighting">(layer.options.name); - -expectType>(layer.animateDarkness()); -expectType>(layer.animateDarkness(1.0)); -expectType>(layer.animateDarkness(1.0, {})); -expectType>(layer.animateDarkness(1.0, { duration: 10000 })); diff --git a/test-d/foundry/client/pixi/layers/map.test-d.ts b/test-d/foundry/client/pixi/layers/map.test-d.ts deleted file mode 100644 index 05c50dd0d..000000000 --- a/test-d/foundry/client/pixi/layers/map.test-d.ts +++ /dev/null @@ -1,41 +0,0 @@ -import type EmbeddedCollection from "../../../../../src/foundry/common/abstract/embedded-collection.mjs"; - -import { expectError, expectType } from "tsd"; - -expectType<"Tile">(MapLayer.documentName); -expectType(MapLayer.layerOptions); -expectType<"background" | "foreground">(MapLayer.layerOptions.name); -expectType(MapLayer.layerOptions.objectClass); - -expectType(new MapLayer()); -expectType(new MapLayer({ bgPath: "/path/to/an/image.png", level: 1 })); - -const layer = new MapLayer(); -expectType>(layer.options); -expectType<"background">(layer.options.name); -expectType(layer.level); -expectType(layer.bgPath); -expectType(layer.bg); -expectType(layer.bgSource); -expectType(layer.hud); -expectType(layer.isVideo); -expectType(layer.tiles); -expectType(layer.deactivate()); -expectType>(layer.tearDown()); -expectType>(layer.draw()); - -expectType>(BackgroundLayer.layerOptions); - -const bgLayer = new BackgroundLayer(); -expectType<"background">(bgLayer.options.name); -expectType | TileDocument[]>(bgLayer.getDocuments()); -expectType(bgLayer.storeHistory("create", new TileDocument().data)); -expectType(bgLayer.storeHistory("update", new TileDocument().data)); -expectType(bgLayer.storeHistory("delete", new TileDocument().data)); -expectError(bgLayer.storeHistory("new", new TileDocument().data)); - -expectType>(ForegroundLayer.layerOptions); - -const fgLayer = new ForegroundLayer(); -expectType<"foreground">(fgLayer.options.name); -expectType | TileDocument[]>(fgLayer.getDocuments()); diff --git a/test-d/foundry/client/pixi/layers/notes.test-d.ts b/test-d/foundry/client/pixi/layers/notes.test-d.ts deleted file mode 100644 index dff842f73..000000000 --- a/test-d/foundry/client/pixi/layers/notes.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; - -expectType(NotesLayer.instance); -expectType(NotesLayer.layerOptions.objectClass); - -const layer = new NotesLayer(); -expectType(layer.options.objectClass); -expectType(layer.options); -expectType<"notes">(layer.options.name); diff --git a/test-d/foundry/client/pixi/layers/sounds.test-d.ts b/test-d/foundry/client/pixi/layers/sounds.test-d.ts deleted file mode 100644 index 2ccda628c..000000000 --- a/test-d/foundry/client/pixi/layers/sounds.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; - -expectType(SoundsLayer.instance); -expectType(SoundsLayer.layerOptions.objectClass); - -const layer = new SoundsLayer(); -expectType(layer.options.objectClass); -expectType(layer.options); -expectType<"sounds">(layer.options.name); diff --git a/test-d/foundry/client/pixi/layers/templates.test-d.ts b/test-d/foundry/client/pixi/layers/templates.test-d.ts deleted file mode 100644 index 1f34afc7e..000000000 --- a/test-d/foundry/client/pixi/layers/templates.test-d.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { expectType } from "tsd"; - -expectType<"MeasuredTemplate">(TemplateLayer.documentName); -expectType(TemplateLayer.instance); -expectType(TemplateLayer.layerOptions); -expectType<"templates">(TemplateLayer.layerOptions.name); -expectType(TemplateLayer.layerOptions.objectClass); -expectType(TemplateLayer.registerSettings()); - -const layer = new TemplateLayer(); -expectType(layer.options.objectClass); -expectType(layer.options); -expectType<"templates">(layer.options.name); -expectType(layer.activate()); -expectType(layer.deactivate()); diff --git a/test-d/foundry/client/pixi/layers/tokens.test-d.ts b/test-d/foundry/client/pixi/layers/tokens.test-d.ts deleted file mode 100644 index de410e9ca..000000000 --- a/test-d/foundry/client/pixi/layers/tokens.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; - -expectType(TokenLayer.instance); -expectType(TokenLayer.layerOptions.objectClass); - -const layer = new TokenLayer(); -expectType(layer.options.objectClass); -expectType(layer.options); -expectType<"tokens">(layer.options.name); diff --git a/test-d/foundry/client/pixi/layers/walls.test-d.ts b/test-d/foundry/client/pixi/layers/walls.test-d.ts deleted file mode 100644 index 618b779ab..000000000 --- a/test-d/foundry/client/pixi/layers/walls.test-d.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { expectType } from "tsd"; - -expectType(WallsLayer.instance); -expectType(WallsLayer.layerOptions.objectClass); - -const layer = new WallsLayer(); -expectType(layer.options.objectClass); -expectType(layer.options); -expectType<"walls">(layer.options.name); - -expectType(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }))); -expectType(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { type: "move" })); -expectType(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { type: "sight" })); -expectType(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { type: "sound" })); -expectType(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { mode: "any" })); - -expectType( - layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { mode: "closest" }), -); -expectType( - layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { mode: "all" }), -); - -expectType>(layer.pasteObjects({ x: 900, y: 800 })); -expectType>(layer.pasteObjects({ x: 900, y: 800 }, {})); -expectType>(layer.pasteObjects({ x: 900, y: 800 }, { hidden: true, snap: true })); diff --git a/test-d/foundry/client/pixi/perception/clockwise-sweep.test-d.ts b/test-d/foundry/client/pixi/perception/clockwise-sweep.test-d.ts deleted file mode 100644 index ea909c4b9..000000000 --- a/test-d/foundry/client/pixi/perception/clockwise-sweep.test-d.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { expectType } from "tsd"; - -const someRay = new Ray({ x: 0, y: 0 }, { x: 0, y: 0 }); -const somePolygonRay: PolygonRay = someRay as PolygonRay; -somePolygonRay.result = new CollisionResult(); - -expectType(ClockwiseSweepPolygon.getRayCollisions(somePolygonRay, { mode: "any" })); -expectType(ClockwiseSweepPolygon.getRayCollisions(somePolygonRay, { mode: "closest" })); -expectType(ClockwiseSweepPolygon.getRayCollisions(somePolygonRay, { mode: "all" })); - -declare const initializedConfig: ClockwiseSweepPolygon.InitializedConfig; -expectType(initializedConfig.hasLimitedRadius); -expectType(initializedConfig.radius); -expectType(initializedConfig.radius2); -expectType(initializedConfig.radiusE); -expectType(initializedConfig.aMin); -expectType(initializedConfig.aMax); -expectType(initializedConfig.angle); -expectType(initializedConfig.rotation); -expectType(initializedConfig.hasLimitedAngle); -expectType(initializedConfig.density); -expectType(initializedConfig.rMax); -expectType(initializedConfig.rMin); -declare const limitedAngleConfig: ClockwiseSweepPolygon.LimitedAngleConfig; -expectType(limitedAngleConfig.hasLimitedRadius); -expectType(limitedAngleConfig.radius); -expectType(limitedAngleConfig.radius2); -expectType(limitedAngleConfig.radiusE); -expectType(limitedAngleConfig.aMin); -expectType(limitedAngleConfig.aMax); -expectType(limitedAngleConfig.angle); -expectType(limitedAngleConfig.rotation); -expectType(limitedAngleConfig.hasLimitedAngle); -expectType(limitedAngleConfig.density); -expectType(limitedAngleConfig.rMax); -expectType(limitedAngleConfig.rMin); diff --git a/test-d/foundry/client/pixi/placeables.test-d.ts b/test-d/foundry/client/pixi/placeables.test-d.ts deleted file mode 100644 index de00851cd..000000000 --- a/test-d/foundry/client/pixi/placeables.test-d.ts +++ /dev/null @@ -1,86 +0,0 @@ -import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs"; -import { expectError, expectType } from "tsd"; - -declare class SomeLightLayer extends PlaceablesLayer<"AmbientLight", PlaceablesLayer.LayerOptions<"AmbientLight">> {} - -expectType(SomeLightLayer.instance); -expectType>(SomeLightLayer.layerOptions); -expectType(SomeLightLayer.layerOptions.objectClass); // TODO: Can this be typed to DocumentConstructor? -expectType<"AmbientLight" | "AmbientSound" | "Drawing" | "MeasuredTemplate" | "Note" | "Tile" | "Token" | "Wall">( - PlaceablesLayer.documentName, -); -expectType>(PlaceablesLayer.placeableClass); - -const layer = new SomeLightLayer(); -expectType(layer.options.objectClass); -expectType(layer.objects); -expectType(layer.preview); -expectType }>>( - layer.history, -); -expectType | null>(layer.quadtree); -expectType | null>(layer.documentCollection); -expectType(layer.gridPrecision); -expectType | null>(layer.hud); -expectType(layer.placeables); -expectType(layer.controlled); -expectType | AmbientLightDocument[]>( - layer.getDocuments(), -); -expectType>(layer.draw()); -expectType(layer.createObject(new AmbientLightDocument())); -expectError(layer.createObject({})); -expectError(layer.createObject()); -expectType>(layer.tearDown()); -expectType(layer.activate()); -expectType(layer.deactivate()); -expectType(layer.get("id")); -expectType(layer.controlAll()); -expectType(layer.controlAll({})); -expectType(layer.controlAll({ releaseOthers: true })); -expectType(layer.releaseAll()); -expectType(layer.releaseAll({})); -expectType(layer.releaseAll({ trigger: true })); -expectType>(layer.rotateMany()); -expectType>(layer.rotateMany({})); -expectType>(layer.rotateMany({ angle: 10, delta: 20, snap: 20, ids: ["abc", "def"] })); -expectType | undefined>(layer.moveMany()); -expectType | undefined>(layer.moveMany({})); -expectType | undefined>( - layer.moveMany({ dx: 100, dy: 100, rotate: true, ids: ["abc", "def"] }), -); -expectType>(layer.undoHistory()); -expectType>(layer.deleteAll()); -expectType(layer.storeHistory("create", new AmbientLightDocument().data)); -expectType(layer.storeHistory("update", new AmbientLightDocument().data)); -expectType(layer.storeHistory("delete", new AmbientLightDocument().data)); -expectError(layer.storeHistory("new", new AmbientLightDocument().data)); -expectType(layer.copyObjects()); -expectType>(layer.pasteObjects({ x: 10, y: 10 })); -expectType>(layer.pasteObjects({ x: 10, y: 10 }, { hidden: true, snap: false })); -expectType>(layer.pasteObjects({ x: 10, y: 10 }, { hidden: false })); -expectType>(layer.pasteObjects({ x: 10, y: 10 }, { snap: true })); -expectType(layer.selectObjects()); -expectType(layer.selectObjects({})); -expectType( - layer.selectObjects({ - x: 10, - y: 10, - width: 100, - height: 200, - releaseOptions: { trigger: true }, - controlOptions: { releaseOthers: true }, - }), -); - -declare function transformer(doc: AmbientLight): Partial; -declare function filter(doc: AmbientLight): boolean; -expectType>(layer.updateAll({ x: 10, y: 20 })); -expectType>(layer.updateAll({ x: 10, y: 20 }, null, {})); -expectType>(layer.updateAll({ x: 10, y: 20 }, filter)); -expectType>(layer.updateAll({ x: 10, y: 20 }, filter, { diff: false, noHook: false })); -expectType>(layer.updateAll(transformer)); -expectType>(layer.updateAll(transformer, null, {})); -expectType>(layer.updateAll(transformer, filter)); -expectType>(layer.updateAll(transformer, filter, { diff: true, noHook: true })); -expectError(layer.updateAll({ no_light_data: 0 })); diff --git a/test-d/foundry/client/pixi/placeables/drawing.test-d.ts b/test-d/foundry/client/pixi/placeables/drawing.test-d.ts deleted file mode 100644 index 89d2dd392..000000000 --- a/test-d/foundry/client/pixi/placeables/drawing.test-d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { expectType } from "tsd"; - -expectType<"Drawing">(Drawing.embeddedName); - -const drawing = new Drawing(new DrawingDocument()); - -expectType(drawing.drawing); -expectType(drawing.shape); -expectType(drawing.text); -expectType(drawing.frame); - -expectType(drawing.isTiled); -expectType(drawing.isPolygon); - -expectType>(drawing.draw()); - -expectType(drawing.refresh()); - -expectType(drawing.activateListeners()); diff --git a/test-d/foundry/client/pixi/placeables/light.test-d.ts b/test-d/foundry/client/pixi/placeables/light.test-d.ts deleted file mode 100644 index 1ed62bdb0..000000000 --- a/test-d/foundry/client/pixi/placeables/light.test-d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { expectType } from "tsd"; - -declare const doc: AmbientLightDocument; - -expectType<"AmbientLight">(AmbientLight.embeddedName); - -const light = new AmbientLight(doc); -expectType(light.source); -expectType(light.controlIcon); -expectType(light.bounds); -expectType(light.global); -expectType(light.radius); -expectType(light.dimRadius); -expectType(light.brightRadius); -expectType(light.isVisible); -expectType>(light.draw()); -expectType(light.refresh()); -expectType(light.refreshControl()); -expectType(light.sourceId); diff --git a/test-d/foundry/client/pixi/placeables/note.test-d.ts b/test-d/foundry/client/pixi/placeables/note.test-d.ts deleted file mode 100644 index 1547a6831..000000000 --- a/test-d/foundry/client/pixi/placeables/note.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -declare const doc: NoteDocument; - -expectType<"Note">(Note.embeddedName); - -const note = new Note(doc); -expectType(note.entry); -expectType(note.text); -expectType(note.size); -expectType>(note.draw()); diff --git a/test-d/foundry/client/pixi/placeables/sound.test-d.ts b/test-d/foundry/client/pixi/placeables/sound.test-d.ts deleted file mode 100644 index ba11cd9fa..000000000 --- a/test-d/foundry/client/pixi/placeables/sound.test-d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expectError, expectType } from "tsd"; - -declare const doc: AmbientSoundDocument; - -expectType<"AmbientSound">(AmbientSound.embeddedName); - -expectError(new AmbientSound()); - -const sound = new AmbientSound(doc); -expectType(sound.sound); -expectType(sound.isAudible); -expectType(sound.radius); -expectType(sound.sync(true, 10)); -expectType(sound.sync(true, 10, {})); -expectType(sound.sync(true, 10, { fade: 250 })); -expectType(sound.clear()); -expectType>(sound.draw()); -expectType(sound.drawField()); -expectType(sound.refresh()); -expectType(sound.refreshControl()); -expectType(sound.updateSource()); diff --git a/test-d/foundry/client/pixi/placeables/template.test-d.ts b/test-d/foundry/client/pixi/placeables/template.test-d.ts deleted file mode 100644 index 1967168c8..000000000 --- a/test-d/foundry/client/pixi/placeables/template.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -expectType<"MeasuredTemplate">(MeasuredTemplate.embeddedName); - -const template = new MeasuredTemplate(new MeasuredTemplateDocument()); -expectType>(template.draw()); -expectType(template.refresh()); -expectType(template.data); - -// TODO: Modify to the configured document sheet once the data can be grabbed from config -expectType(template.sheet); diff --git a/test-d/foundry/client/pixi/placeables/tile.test-d.ts b/test-d/foundry/client/pixi/placeables/tile.test-d.ts deleted file mode 100644 index 5b2d95e32..000000000 --- a/test-d/foundry/client/pixi/placeables/tile.test-d.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { expectType } from "tsd"; - -expectType<"Tile">(Tile.embeddedName); -expectType(Tile.createPreview({ x: 100, y: null })); - -declare const doc: TileDocument; -const tile = new Tile(doc); -declare const token: Token; - -expectType(tile.frame); -expectType(tile.texture); -expectType(tile.tile); -expectType(tile.bg); -expectType(tile.occluded); -expectType(tile.aspectRatio); -expectType(tile.sourceElement); -expectType(tile.isVideo); -expectType(tile.isRoof); -expectType>(tile.draw()); -expectType(tile.refresh()); - -expectType(tile.play(true)); -expectType(tile.play(false, {})); -expectType(tile.play(false, { loop: true, offset: 10, volume: 10 })); - -expectType(tile.updateOcclusion([token])); - -expectType(tile.testOcclusion(token)); -expectType(tile.testOcclusion(token, {})); -expectType(tile.testOcclusion(token, { corners: false })); - -expectType(tile.containsPixel(236, 154)); - -expectType(tile.getRoofSprite()); -expectType(tile.swapLayer()); -expectType(tile.activateListeners()); diff --git a/test-d/foundry/client/pixi/placeables/token.test-d.ts b/test-d/foundry/client/pixi/placeables/token.test-d.ts deleted file mode 100644 index de06535a0..000000000 --- a/test-d/foundry/client/pixi/placeables/token.test-d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import type { ConfiguredDocumentClass } from "../../../../../src/types/helperTypes"; - -import { expectType } from "tsd"; - -const token = new Token(new TokenDocument()); -expectType(token.id); -expectType(token.actor); -expectType(token.data.actorId); -expectType(token.data.actorLink); -expectType(token.data.x); -expectType(token.data.y); -expectType(token.data.hidden); -expectType(token.emitsLight); -expectType>[]>>(token.toggleVisibility()); -expectType>(token.toggleEffect(CONFIG.statusEffects[0])); -expectType>(token.toggleEffect(new ActiveEffect().data)); -expectType>(token.toggleEffect("path/to/my/image.png")); diff --git a/test-d/foundry/client/pixi/placeables/wall.test-d.ts b/test-d/foundry/client/pixi/placeables/wall.test-d.ts deleted file mode 100644 index 4d486e7bc..000000000 --- a/test-d/foundry/client/pixi/placeables/wall.test-d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { expectType } from "tsd"; - -expectType<"Wall">(Wall.embeddedName); - -declare const doc: WallDocument; -declare const ray: Ray; - -const wall = new Wall(doc); -expectType(wall.doorControl); -expectType | null>(wall.mouseInteractionManager); -expectType(wall.roof); -expectType<[number, number, number, number]>(wall.coords); -expectType(wall.bounds); -expectType<[number, number]>(wall.midpoint); -expectType(wall.center); -expectType(wall.direction); -expectType(wall.toRay()); -expectType>(wall.draw()); -expectType(wall.isDirectionBetweenAngles(10, 20)); -expectType(wall.canRayIntersect(ray)); -expectType<{ ids: string[]; walls: Wall[]; endpoints: Array<[number, number]> }>(wall.getLinkedSegments()); diff --git a/test-d/foundry/client/pixi/webgl/filters.test-d.ts b/test-d/foundry/client/pixi/webgl/filters.test-d.ts deleted file mode 100644 index eaa47c82f..000000000 --- a/test-d/foundry/client/pixi/webgl/filters.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectType } from "tsd"; - -class CustomMaskFilter extends AbstractBaseMaskFilter {} - -expectType(CustomMaskFilter.create()); - -expectType(InverseOcclusionMaskFilter.create()); diff --git a/test-d/foundry/client/ui/drag.test-d.ts b/test-d/foundry/client/ui/drag.test-d.ts deleted file mode 100644 index 3c61d5e52..000000000 --- a/test-d/foundry/client/ui/drag.test-d.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { expectType } from "tsd"; -import "../../index"; - -const App = class extends Application {}; -const resizableUndefined = new Draggable(new App(), $(), new HTMLElement()); -expectType(resizableUndefined.resizable); -expectType(resizableUndefined.handlers); - -const maybeResizable = new Draggable(new App(), $(), new HTMLElement(), ((): boolean => false)()); -expectType(maybeResizable.resizable); -expectType(maybeResizable.handlers); - -const nonResizable = new Draggable(new App(), $(), new HTMLElement(), false); -expectType(nonResizable.resizable); -expectType(nonResizable.handlers); - -const resizable = new Draggable(new App(), $(), new HTMLElement(), true); -expectType(resizable.resizable); -expectType(resizable.handlers); diff --git a/test-d/foundry/client/ui/filter.test-d.ts b/test-d/foundry/client/ui/filter.test-d.ts deleted file mode 100644 index 1217fff89..000000000 --- a/test-d/foundry/client/ui/filter.test-d.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new SearchFilter()); -expectError(new SearchFilter({})); -expectType( - new SearchFilter({ - inputSelector: "input", - contentSelector: ".my-class", - callback: (event: KeyboardEvent, query: string, rgx: RegExp, content: string): void => { - rgx.exec(content); - }, - }), -); -const filter = new SearchFilter({ - inputSelector: "input", - contentSelector: ".my-class", - callback: (event: KeyboardEvent, query: string, rgx: RegExp, content: string): void => { - rgx.exec(content); - }, - initial: "Type here", - delay: 100, -}); - -expectType(filter.query); -expectType<(event: KeyboardEvent, query: string, rgx: RegExp, content: string) => void>(filter.callback); -expectType(filter.rgx); -expectType(filter.bind(new HTMLDivElement())); -expectType(filter.filter(new KeyboardEvent("keyup"), "Typed")); - -expectType(SearchFilter.cleanQuery(" my-query")); diff --git a/test-d/foundry/client/ui/notifications.test-d.ts b/test-d/foundry/client/ui/notifications.test-d.ts deleted file mode 100644 index 4965c2342..000000000 --- a/test-d/foundry/client/ui/notifications.test-d.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { expectError, expectType } from "tsd"; - -const notifcations = new Notifications(); -expectType< - Array<{ - message: string; - type: "info" | "warning" | "error"; - timestamp: number; - console: boolean; - permanent: boolean; - }> ->(notifcations.queue); -expectType(notifcations.active); - -expectType(notifcations.notify("Hello world")); -expectType(notifcations.notify("Hello world", "info")); -expectType(notifcations.notify("Hello world", "warning")); -expectType(notifcations.notify("Hello world", "error")); -expectError(notifcations.notify("Hello world", "success")); -expectType(notifcations.notify("Hello world", "error", { localize: true })); -expectType(notifcations.notify("Hello world", "error", { permanent: true })); -expectType(notifcations.notify("Hello world", "error", { console: false })); - -expectType(notifcations.info("Hello world")); -expectType(notifcations.info("Hello world", { localize: true })); -expectType(notifcations.info("Hello world", { permanent: true })); -expectType(notifcations.info("Hello world", { console: false })); - -expectType(notifcations.warn("Hello world")); -expectType(notifcations.warn("Hello world", { localize: true })); -expectType(notifcations.warn("Hello world", { permanent: true })); -expectType(notifcations.warn("Hello world", { console: false })); - -expectType(notifcations.error("Hello world")); -expectType(notifcations.error("Hello world", { localize: true })); -expectType(notifcations.error("Hello world", { permanent: true })); -expectType(notifcations.error("Hello world", { console: false })); diff --git a/test-d/foundry/client/ui/prosemirror.test-d.ts b/test-d/foundry/client/ui/prosemirror.test-d.ts deleted file mode 100644 index 895999012..000000000 --- a/test-d/foundry/client/ui/prosemirror.test-d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { expectAssignable, expectError } from "tsd"; - -expectAssignable(ProseMirrorEditor); -type ProseMirrorEditorCreateFuncOptions = Parameters<(typeof ProseMirrorEditor)["create"]>[2]; -declare const document: Actor; - -// if collaborate is true, both document and fieldName are expected to be present. -expectError({ collaborate: true }); -expectError({ collaborate: true, document }); -expectError({ collaborate: true, fieldName: "error" }); -expectAssignable({ collaborate: true, document: document, fieldName: "valid" }); -expectAssignable({}); -expectAssignable({ collaborate: false }); diff --git a/test-d/foundry/client/ui/tabs.test-d.ts b/test-d/foundry/client/ui/tabs.test-d.ts deleted file mode 100644 index 4cc883bfa..000000000 --- a/test-d/foundry/client/ui/tabs.test-d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new Tabs()); -expectError(new Tabs({})); -expectType(new Tabs({ navSelector: ".tabs" })); -const tabs = new Tabs({ - navSelector: ".tabs", - contentSelector: ".content", - initial: "tab1", - callback: (event: MouseEvent | null, tabs: Tabs, active: string): void => { - console.log(active); - }, -}); - -expectType(tabs.active); -expectType<((event: MouseEvent | null, tabs: Tabs, tabName: string) => unknown) | null | undefined>(tabs.callback); - -tabs.bind(new HTMLDivElement()); -tabs.activate("tab1"); -tabs.activate("tab1", {}); -tabs.activate("tab1", { triggerCallback: true }); - -expectType(TabsV2); diff --git a/test-d/foundry/common/abstract/data.mjs.test-d.ts b/test-d/foundry/common/abstract/data.mjs.test-d.ts deleted file mode 100644 index 23323c986..000000000 --- a/test-d/foundry/common/abstract/data.mjs.test-d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import type { - EffectChangeData, - EffectChangeDataProperties, -} from "../../../../src/foundry/common/data/data.mjs/effectChangeData"; - -import { expectError, expectType } from "tsd"; -import "../../../../index"; - -expectError(new foundry.data.ActorData()); -expectError(new foundry.data.ActorData({})); - -const activeEffectData = new foundry.data.ActiveEffectData(); -expectType(activeEffectData.toJSON().changes); -expectType(activeEffectData.toObject().changes); -expectType(activeEffectData.toObject(true).changes); -expectType(activeEffectData.toObject(false).changes); diff --git a/test-d/foundry/common/abstract/document.mjs.test-d.ts b/test-d/foundry/common/abstract/document.mjs.test-d.ts deleted file mode 100644 index f3397dc05..000000000 --- a/test-d/foundry/common/abstract/document.mjs.test-d.ts +++ /dev/null @@ -1,117 +0,0 @@ -import type { ActiveEffectDataSource } from "../../../../src/foundry/common/data/data.mjs/activeEffectData"; -import type { - EffectChangeData, - EffectChangeDataProperties, -} from "../../../../src/foundry/common/data/data.mjs/effectChangeData"; -import { expectError, expectType } from "tsd"; - -const baseActiveEffect = new foundry.documents.BaseActiveEffect(); - -expectType(baseActiveEffect.toJSON().changes); -expectType(baseActiveEffect.toObject().changes); -expectType(baseActiveEffect.toObject(true).changes); -expectType(baseActiveEffect.toObject(false).changes); - -const item = await Item.create({ name: "Some Item", type: "weapon" }); -if (item) { - expectType(item.toObject(false).effects[0].changes); - expectType(item.toObject().effects); -} - -declare const bool: boolean; - -expectType>(foundry.documents.BaseMacro.create({ name: "" }, { temporary: bool })); -expectType>(foundry.documents.BaseMacro.create({ name: "" }, { temporary: true })); -expectType | undefined>>(foundry.documents.BaseMacro.create({ name: "" })); -expectType | undefined>>( - foundry.documents.BaseMacro.create({ name: "" }, { temporary: false }), -); - -expectType>(foundry.documents.BaseMacro.createDocuments([], { temporary: bool })); -expectType>(foundry.documents.BaseMacro.createDocuments([], { temporary: true })); -expectType[]>>(foundry.documents.BaseMacro.createDocuments([])); -expectType[]>>(foundry.documents.BaseMacro.createDocuments([], { temporary: false })); - -expectType>(foundry.documents.BaseMacro.updateDocuments([])); -expectType>(foundry.documents.BaseMacro.deleteDocuments([])); -const user = await User.create({ name: "Some User" }); -if (user) { - expectType(user.testUserPermission(user, "NONE")); - expectType(user.testUserPermission(user, "OBSERVER", {})); - expectType(user.testUserPermission(user, "LIMITED", { exact: true })); - expectType(user.testUserPermission(user, "OWNER", { exact: false })); -} - -// test creation of embedded documents -declare const actor: Actor; -expectType[]>>( - actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: true }), -); -expectType[]>>( - actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: bool }), -); -expectType>[]>>( - actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: false }), -); -expectType>[]>>( - actor.createEmbeddedDocuments("ActiveEffect", []), -); - -// verify that document lifecycle methods work with source data is possible - -if (item) { - expectType[]>>(Item.createDocuments([item.toObject()])); - expectType | undefined>>(Item.create(item.toObject())); - expectType>(Item.updateDocuments([item.toObject()])); - expectType | undefined>>(item.update(item.toObject())); - expectType>(item.clone(item.toObject())); -} - -declare global { - interface FlagConfig { - Combatant: { - "my-system": { - value: boolean; - value2: number; - }; - "my-optional-system"?: { - value: boolean; - }; - }; - } -} - -const combatant = new Combatant({}, {}); -expectType<{ value: boolean; value2: number }>(combatant.data.flags["my-system"]); -expectType<{ value: boolean } | undefined>(combatant.data.flags["my-optional-system"]); - -expectType(combatant.getFlag("my-system", "value")); -expectType(combatant.getFlag("my-system", "value2")); -expectType(combatant.getFlag("my-system", "unknown-key")); -expectType(combatant.getFlag("another-system", "value")); -expectType(combatant.getFlag("my-optional-system", "value")); - -expectType>(combatant.setFlag("my-system", "value", true)); -expectError(combatant.setFlag("my-system", "value", 2)); -expectError(combatant.setFlag("my-system", "unknown-key", 2)); -expectType>(combatant.setFlag("my-optional-system", "value", true)); -expectError(combatant.setFlag("my-optional-system", "value", undefined)); -expectType>(combatant.setFlag("another-system", "value", true)); - -expectType>(combatant.unsetFlag("my-system", "value")); -expectType>(combatant.unsetFlag("my-optional-system", "value")); -expectType>(combatant.unsetFlag("another-system", "value")); - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -class MyCombatant extends Combatant { - setSomeFlag() { - expectType<{ value: boolean; value2: number }>(this.data.flags["my-system"]); - expectType<{ value: boolean } | undefined>(this.data.flags["my-optional-system"]); - - expectType(this.getFlag("my-system", "value")); - expectType(this.getFlag("another-system", "value")); - - expectType>(this.setFlag("my-system", "value", true)); - expectType>(this.setFlag("another-system", "value", true)); - } -} diff --git a/test-d/foundry/common/data/data.mjs/actorData.test-d.ts b/test-d/foundry/common/data/data.mjs/actorData.test-d.ts deleted file mode 100644 index 7a319c807..000000000 --- a/test-d/foundry/common/data/data.mjs/actorData.test-d.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { expectError, expectType } from "tsd"; -import "../../../../../index"; - -interface CharacterDataSourceData { - health: number; -} - -interface CharacterFlags { - "my-module": { - known: boolean; - xp: number; - }; -} - -interface CharacterDataSource { - type: "character"; - data: CharacterDataSourceData; - flags: CharacterFlags; -} - -interface CharacterDataPropertiesData extends CharacterDataSourceData { - movement: number; -} - -interface CharacterDataProperties { - type: "character"; - data: CharacterDataPropertiesData; - flags: CharacterFlags; -} - -interface NPCDataSourceData { - challenge: number; - faction: string; -} - -interface NPCFlags { - "my-module": { - "hidden-name": string; - known: boolean; - }; -} - -interface NPCDataSource { - type: "npc"; - data: NPCDataSourceData; - flags: NPCFlags; -} - -interface NPCDataPropertiesData extends NPCDataSourceData { - damage: number; -} - -interface NPCDataProperties { - type: "npc"; - data: NPCDataPropertiesData; - flags: NPCFlags; -} - -type MyActorDataSource = CharacterDataSource | NPCDataSource; -type MyActorDataProperties = CharacterDataProperties | NPCDataProperties; - -declare global { - interface DataConfig { - Actor: MyActorDataProperties; - } - - interface SourceConfig { - Actor: MyActorDataSource; - } -} - -expectError(new foundry.data.ActorData()); -expectError(new foundry.data.ActorData({})); - -expectError(new foundry.data.ActorData({ name: "Some Actor With Wrong Type", type: "foo" })); - -const actorData = new foundry.data.ActorData({ name: "Some Actor", type: "character" }); - -expectType(actorData); -expectType<"character" | "npc">(actorData.type); -if (actorData._source.type === "character") { - expectType(actorData._source.data.health); - expectError(actorData._source.data.movement); - expectType(actorData._source.flags["my-module"].xp); -} else { - expectType(actorData._source.data.faction); - expectType(actorData._source.data.challenge); - expectError(actorData._source.data.damage); - expectType(actorData._source.flags["my-module"]["hidden-name"]); -} - -if (actorData.type === "character") { - expectType(actorData.data.health); - expectType(actorData.data.movement); - expectType(actorData.flags["my-module"].xp); -} else { - expectType(actorData.data.faction); - expectType(actorData.data.challenge); - expectType(actorData.data.damage); - expectType(actorData.flags["my-module"]["hidden-name"]); -} diff --git a/test-d/foundry/common/data/data.mjs/cardsData.test-d.ts b/test-d/foundry/common/data/data.mjs/cardsData.test-d.ts deleted file mode 100644 index 324f52d93..000000000 --- a/test-d/foundry/common/data/data.mjs/cardsData.test-d.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { expectError, expectType } from "tsd"; - -interface GermanDeckDataSourceData { - mostUsedGame: "Skat"; -} - -interface GermanDeckDataSource { - type: "german"; - data: GermanDeckDataSourceData; -} - -interface FrenchDeckDataSourceData { - coolUse: "throwing cards"; -} - -interface FrenchDeckDataSource { - type: "french"; - data: FrenchDeckDataSourceData; -} - -interface GermanDeckDataPropertiesData extends GermanDeckDataSourceData { - mostUsedBy: "older players"; -} - -interface GermanDeckDataProperties { - type: "german"; - data: GermanDeckDataPropertiesData; -} - -interface FrenchDeckDataPropertiesData extends FrenchDeckDataSourceData { - possibleInjuries: "card stuck in eye"; -} - -interface FrenchDeckDataProperties { - type: "french"; - data: FrenchDeckDataPropertiesData; -} - -type MyCardsDataSource = GermanDeckDataSource | FrenchDeckDataSource; -type MyCardsDataProperties = GermanDeckDataProperties | FrenchDeckDataProperties; - -declare global { - interface DataConfig { - Cards: MyCardsDataProperties; - } - - interface SourceConfig { - Cards: MyCardsDataSource; - } -} - -expectError(new foundry.data.CardsData()); -expectError(new foundry.data.CardsData({})); -expectType(new foundry.data.CardsData({ name: "Some Cards" })); - -expectError(new foundry.data.CardsData({ name: "Some Cards With Wrong Type", type: "foo" })); - -const cardsData = new foundry.data.CardsData({ name: "Some Deck", type: "french" }); - -expectType(cardsData); -expectType<"french" | "german">(cardsData.type); -if (cardsData._source.type === "french") { - expectType<"throwing cards">(cardsData._source.data.coolUse); - expectError(cardsData._source.data.possibleInjuries); -} else { - expectType<"Skat">(cardsData._source.data.mostUsedGame); - expectError(cardsData._source.data.mostUsedBy); -} - -if (cardsData.type === "french") { - expectType<"throwing cards">(cardsData.data.coolUse); - expectType<"card stuck in eye">(cardsData.data.possibleInjuries); -} else { - expectType<"Skat">(cardsData.data.mostUsedGame); - expectType<"older players">(cardsData.data.mostUsedBy); -} diff --git a/test-d/foundry/common/data/data.mjs/combatData.test-d.ts b/test-d/foundry/common/data/data.mjs/combatData.test-d.ts deleted file mode 100644 index 179bf3dc8..000000000 --- a/test-d/foundry/common/data/data.mjs/combatData.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectType } from "tsd"; - -expectType(new foundry.data.CombatData()); -expectType(new foundry.data.CombatData({})); -expectType(new foundry.data.CombatData({ scene: "foo", active: true })); diff --git a/test-d/foundry/common/data/data.mjs/combatantData.test-d.ts b/test-d/foundry/common/data/data.mjs/combatantData.test-d.ts deleted file mode 100644 index 5ad468d25..000000000 --- a/test-d/foundry/common/data/data.mjs/combatantData.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectType } from "tsd"; - -expectType(new foundry.data.CombatantData()); -expectType(new foundry.data.CombatantData({})); -expectType(new foundry.data.CombatantData({ tokenId: "foo", actorId: "bar" })); diff --git a/test-d/foundry/common/data/data.mjs/folderData.test-d.ts b/test-d/foundry/common/data/data.mjs/folderData.test-d.ts deleted file mode 100644 index 311bffa78..000000000 --- a/test-d/foundry/common/data/data.mjs/folderData.test-d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new foundry.data.FolderData()); -expectError(new foundry.data.FolderData({})); -expectError(new foundry.data.FolderData({ name: "foo", type: "foo" })); -expectType( - new foundry.data.FolderData({ name: "foo", type: foundry.CONST.FOLDER_DOCUMENT_TYPES[0] }), -); diff --git a/test-d/foundry/common/data/data.mjs/itemData.test-d.ts b/test-d/foundry/common/data/data.mjs/itemData.test-d.ts deleted file mode 100644 index 94d9f2b00..000000000 --- a/test-d/foundry/common/data/data.mjs/itemData.test-d.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { expectError, expectType } from "tsd"; -import "../../../../../index"; - -interface ArmorDataSourceData { - armorValue: number; -} - -interface ArmorDataSource { - type: "armor"; - data: ArmorDataSourceData; -} - -interface WeaponDataSourceData { - damagePerHit: number; - attackSpeed: number; -} - -interface WeaponDataSource { - type: "weapon"; - data: WeaponDataSourceData; -} - -interface ArmorDataPropertiesData extends ArmorDataSourceData { - weight: number; -} - -interface ArmorDataProperties { - type: "armor"; - data: ArmorDataPropertiesData; -} - -interface WeaponDataPropertiesData extends WeaponDataSourceData { - damage: number; -} - -interface WeaponDataProperties { - type: "weapon"; - data: WeaponDataPropertiesData; -} - -type MyItemDataSource = ArmorDataSource | WeaponDataSource; -type MyItemDataProperties = ArmorDataProperties | WeaponDataProperties; - -declare global { - interface DataConfig { - Item: MyItemDataProperties; - } - - interface SourceConfig { - Item: MyItemDataSource; - } -} - -expectError(new foundry.data.ItemData()); -expectError(new foundry.data.ItemData({})); - -expectError(new foundry.data.ItemData({ name: "Some Item With Wrong Type", type: "foo" })); - -const itemData = new foundry.data.ItemData({ name: "Some Item", type: "weapon" }); - -expectType(itemData); -expectType<"weapon" | "armor">(itemData.type); -if (itemData._source.type === "armor") { - expectType(itemData._source.data.armorValue); - expectError(itemData._source.data.weight); -} else { - expectType(itemData._source.data.attackSpeed); - expectType(itemData._source.data.damagePerHit); - expectError(itemData._source.data.damage); -} - -if (itemData.type === "armor") { - expectType(itemData.data.armorValue); - expectType(itemData.data.weight); -} else { - expectType(itemData.data.attackSpeed); - expectType(itemData.data.damagePerHit); - expectType(itemData.data.damage); -} diff --git a/test-d/foundry/common/data/data.mjs/journalEntryData.test-d.ts b/test-d/foundry/common/data/data.mjs/journalEntryData.test-d.ts deleted file mode 100644 index 3fe6e39bf..000000000 --- a/test-d/foundry/common/data/data.mjs/journalEntryData.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new foundry.data.JournalEntryData()); -expectError(new foundry.data.JournalEntryData({})); -expectType(new foundry.data.JournalEntryData({ name: "foo" })); diff --git a/test-d/foundry/common/data/data.mjs/macroData.test-d.ts b/test-d/foundry/common/data/data.mjs/macroData.test-d.ts deleted file mode 100644 index 92ae9ac2e..000000000 --- a/test-d/foundry/common/data/data.mjs/macroData.test-d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new foundry.data.MacroData()); -expectError(new foundry.data.MacroData({})); -expectType(new foundry.data.MacroData({ name: "foo" })); diff --git a/test-d/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts b/test-d/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts deleted file mode 100644 index 119bb2afe..000000000 --- a/test-d/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { expectType } from "tsd"; - -expectType(new foundry.data.PrototypeTokenData()); -expectType(new foundry.data.PrototypeTokenData({})); -expectType(new foundry.data.PrototypeTokenData({ name: "foo" })); -expectType(new foundry.data.PrototypeTokenData({ name: "foo" }).actorLink); -expectType(new foundry.data.PrototypeTokenData({ name: "foo" }).bar1.attribute); diff --git a/test-d/foundry/common/data/data.mjs/settingData.test-d.ts b/test-d/foundry/common/data/data.mjs/settingData.test-d.ts deleted file mode 100644 index ebcf19cf1..000000000 --- a/test-d/foundry/common/data/data.mjs/settingData.test-d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new foundry.data.SettingData()); -expectError(new foundry.data.SettingData({})); -expectError(new foundry.data.SettingData({ key: "foo", value: "bar" })); -expectType(new foundry.data.SettingData({ key: "foo.bar", value: "bar" })); -const namespace = "foo"; -const key = "bar"; -expectType(new foundry.data.SettingData({ key: `${namespace}.${key}`, value: "bar" })); -expectError(new foundry.data.SettingData({ key: namespace + "." + key, value: "bar" })); diff --git a/test-d/foundry/common/data/data.mjs/userData.test-d.ts b/test-d/foundry/common/data/data.mjs/userData.test-d.ts deleted file mode 100644 index 7b0181127..000000000 --- a/test-d/foundry/common/data/data.mjs/userData.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new foundry.data.UserData()); -expectError(new foundry.data.UserData({})); -expectType(new foundry.data.UserData({ name: "foo" })); -expectType(new foundry.data.UserData({ name: "foo", hotbar: { 1: "foo" } })); -expectType(new foundry.data.UserData({ name: "foo", hotbar: { "1": "foo" } })); -expectType(new foundry.data.UserData({ name: "foo", hotbar: { ["1"]: "foo" } })); -expectError(new foundry.data.UserData({ name: "foo", hotbar: { foo: "foo" } })); diff --git a/test-d/foundry/common/data/data.mjs/wallData.test-d.ts b/test-d/foundry/common/data/data.mjs/wallData.test-d.ts deleted file mode 100644 index a555891b1..000000000 --- a/test-d/foundry/common/data/data.mjs/wallData.test-d.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { expectError, expectType } from "tsd"; - -expectError(new foundry.data.WallData()); -expectError(new foundry.data.WallData({})); -expectError(new foundry.data.WallData({ c: [10, 20] })); -expectType(new foundry.data.WallData({ c: [10, 20, 30, 40] })); -expectType( - new foundry.data.WallData({ - _id: null, - c: [10, 20, 30, 40], - light: null, - move: null, - sight: null, - sound: null, - dir: null, - door: null, - ds: null, - flags: null, - }), -); -expectType( - new foundry.data.WallData({ - _id: undefined, - c: [10, 20, 30, 40], - light: undefined, - move: undefined, - sight: undefined, - sound: undefined, - dir: undefined, - door: undefined, - ds: undefined, - flags: undefined, - }), -); -expectType( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - light: foundry.CONST.WALL_SENSE_TYPES.NORMAL, - move: foundry.CONST.WALL_MOVEMENT_TYPES.NORMAL, - sight: foundry.CONST.WALL_SENSE_TYPES.NORMAL, - sound: foundry.CONST.WALL_SENSE_TYPES.NORMAL, - dir: foundry.CONST.WALL_DIRECTIONS.BOTH, - door: foundry.CONST.WALL_DOOR_TYPES.NONE, - ds: foundry.CONST.WALL_DOOR_STATES.CLOSED, - flags: {}, - }), -); -expectError( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - light: 9999, - }), -); -expectError( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - move: 9999, - }), -); -expectError( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - sight: 9999, - }), -); -expectError( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - sound: 9999, - }), -); - -expectError( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - dir: 9999, - }), -); -expectError( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - door: 9999, - }), -); - -expectError( - new foundry.data.WallData({ - c: [10, 20, 30, 40], - ds: 9999, - }), -); diff --git a/test-d/foundry/common/documents.mjs/baseActiveEffect.test-d.ts b/test-d/foundry/common/documents.mjs/baseActiveEffect.test-d.ts deleted file mode 100644 index 732454d1a..000000000 --- a/test-d/foundry/common/documents.mjs/baseActiveEffect.test-d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>(foundry.documents.BaseActiveEffect.create({})); -expectType[]>>(foundry.documents.BaseActiveEffect.createDocuments([])); -expectType>(foundry.documents.BaseActiveEffect.updateDocuments([])); -expectType>(foundry.documents.BaseActiveEffect.deleteDocuments([])); - -const activeEffect = await foundry.documents.BaseActiveEffect.create({}, { temporary: true }); -if (activeEffect) { - expectType(activeEffect.data); - expectType(activeEffect.parent); -} diff --git a/test-d/foundry/common/documents.mjs/baseActor.test-d.ts b/test-d/foundry/common/documents.mjs/baseActor.test-d.ts deleted file mode 100644 index 2195af892..000000000 --- a/test-d/foundry/common/documents.mjs/baseActor.test-d.ts +++ /dev/null @@ -1,116 +0,0 @@ -import { expectError, expectType } from "tsd"; - -import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs"; -import type { ActiveEffectDataSource } from "../../../../src/foundry/common/data/data.mjs/activeEffectData"; -import type { EffectDurationDataProperties } from "../../../../src/foundry/common/data/data.mjs/effectDurationData"; - -const baseActor = new foundry.documents.BaseActor(); -expectType>(baseActor.effects); -expectType>(baseActor.items); -expectType(baseActor.data._source.effects[0]); -expectType(baseActor.data._source.effects[0].duration); - -interface CharacterDataSourceData { - health: number; -} - -interface CharacterFlags { - "my-module": { - known: boolean; - xp: number; - }; -} - -interface CharacterDataSource { - type: "character"; - data: CharacterDataSourceData; - flags: CharacterFlags; -} - -interface CharacterDataPropertiesData extends CharacterDataSourceData { - movement: number; -} - -interface CharacterDataProperties { - type: "character"; - data: CharacterDataPropertiesData; - flags: CharacterFlags; -} - -interface NPCDataSourceData { - challenge: number; - faction: string; -} - -interface NPCFlags { - "my-module": { - "hidden-name": string; - known: boolean; - }; -} - -interface NPCDataSource { - type: "npc"; - data: NPCDataSourceData; - flags: NPCFlags; -} - -interface NPCDataPropertiesData extends NPCDataSourceData { - damage: number; -} - -interface NPCDataProperties { - type: "npc"; - data: NPCDataPropertiesData; - flags: NPCFlags; -} - -type MyActorDataSource = CharacterDataSource | NPCDataSource; -type MyActorDataProperties = CharacterDataProperties | NPCDataProperties; - -declare global { - interface DataConfig { - Actor: MyActorDataProperties; - } - - interface SourceConfig { - Actor: MyActorDataSource; - } -} - -expectType<"character" | "npc">(baseActor.data.type); -expectType(baseActor.items.get("", { strict: true }).parent); - -if (baseActor.data._source.type === "character") { - expectType(baseActor.data._source.data.health); - expectError(baseActor.data._source.data.movement); -} else { - expectType(baseActor.data._source.data.faction); - expectType(baseActor.data._source.data.challenge); - expectError(baseActor.data._source.data.damage); -} - -if (baseActor.data.type === "character") { - expectType(baseActor.data.data.health); - expectType(baseActor.data.data.movement); -} else { - expectType(baseActor.data.data.faction); - expectType(baseActor.data.data.challenge); - expectType(baseActor.data.data.damage); -} - -// Flags for Actor, Items, Card, and Cards documents can be configured via the SourceConfig. This is tested here. -// For configuring flags for actors and items via FlagConfig please have a look into baseItem.test-d.ts. -// shared flags are available -expectType(baseActor.getFlag("my-module", "known")); -// non shared flags are not available -expectType(baseActor.getFlag("my-module", "xp")); -expectType(baseActor.getFlag("my-module", "hidden-name")); -// non shared flags are also not available if the type is known -if (baseActor.data._source.type === "character") { - expectType(baseActor.getFlag("my-module", "xp")); -} -if (baseActor.data.type === "character") { - expectType(baseActor.getFlag("my-module", "xp")); -} -expectType<"Actor">(baseActor.documentName); diff --git a/test-d/foundry/common/documents.mjs/baseChatMessage.test-d.ts b/test-d/foundry/common/documents.mjs/baseChatMessage.test-d.ts deleted file mode 100644 index cdf153c34..000000000 --- a/test-d/foundry/common/documents.mjs/baseChatMessage.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>(foundry.documents.BaseChatMessage.create({})); -expectType[]>>(foundry.documents.BaseChatMessage.createDocuments([])); -expectType>(foundry.documents.BaseChatMessage.updateDocuments([])); -expectType>(foundry.documents.BaseChatMessage.deleteDocuments([])); - -const chat = await foundry.documents.BaseChatMessage.create({}, { temporary: true }); -if (chat) { - expectType(chat.data); -} diff --git a/test-d/foundry/common/documents.mjs/baseCombat.test-d.ts b/test-d/foundry/common/documents.mjs/baseCombat.test-d.ts deleted file mode 100644 index 983852d8c..000000000 --- a/test-d/foundry/common/documents.mjs/baseCombat.test-d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>( - foundry.documents.BaseCombat.create({ scene: "foo", active: true, sort: 1 }), -); -expectType[]>>(foundry.documents.BaseCombat.createDocuments([])); -expectType>(foundry.documents.BaseCombat.updateDocuments([])); -expectType>(foundry.documents.BaseCombat.deleteDocuments([])); - -const combat = await foundry.documents.BaseCombat.create({ scene: "foo", active: true }, { temporary: true }); -if (combat) { - expectType(combat.data); -} diff --git a/test-d/foundry/common/documents.mjs/baseCombatant.test-d.ts b/test-d/foundry/common/documents.mjs/baseCombatant.test-d.ts deleted file mode 100644 index 3ed10d2ab..000000000 --- a/test-d/foundry/common/documents.mjs/baseCombatant.test-d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>( - foundry.documents.BaseCombatant.create({ actorId: "someID", tokenId: "someOtherId" }), -); -expectType[]>>(foundry.documents.BaseCombatant.createDocuments([])); -expectType>(foundry.documents.BaseCombatant.updateDocuments([])); -expectType>(foundry.documents.BaseCombatant.deleteDocuments([])); - -const combatant = await foundry.documents.BaseCombatant.create( - { name: "Another Combatant", type: "Actor" }, - { temporary: true }, -); -if (combatant) { - expectType(combatant.data); -} diff --git a/test-d/foundry/common/documents.mjs/baseDrawing.test-d.ts b/test-d/foundry/common/documents.mjs/baseDrawing.test-d.ts deleted file mode 100644 index a5a8564c7..000000000 --- a/test-d/foundry/common/documents.mjs/baseDrawing.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>(foundry.documents.BaseDrawing.create({})); -expectType[]>>(foundry.documents.BaseDrawing.createDocuments([])); -expectType>(foundry.documents.BaseDrawing.updateDocuments([])); -expectType>(foundry.documents.BaseDrawing.deleteDocuments([])); - -const drawing = await foundry.documents.BaseDrawing.create({}, { temporary: true }); -if (drawing) { - expectType(drawing.data); -} diff --git a/test-d/foundry/common/documents.mjs/baseFogExploration.test-d.ts b/test-d/foundry/common/documents.mjs/baseFogExploration.test-d.ts deleted file mode 100644 index e28f644cc..000000000 --- a/test-d/foundry/common/documents.mjs/baseFogExploration.test-d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { expectType } from "tsd"; - -expectType(new foundry.documents.BaseFogExploration()); -expectType(new foundry.documents.BaseFogExploration({})); -expectType | undefined>>(foundry.documents.BaseFogExploration.create({})); -expectType[]>>(foundry.documents.BaseFogExploration.createDocuments()); -expectType>(foundry.documents.BaseFogExploration.updateDocuments()); -expectType>(foundry.documents.BaseFogExploration.deleteDocuments()); - -const folder = new foundry.documents.BaseFogExploration(); -expectType(folder.data); diff --git a/test-d/foundry/common/documents.mjs/baseFolder.test-d.ts b/test-d/foundry/common/documents.mjs/baseFolder.test-d.ts deleted file mode 100644 index fb6c8668e..000000000 --- a/test-d/foundry/common/documents.mjs/baseFolder.test-d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>( - foundry.documents.BaseFolder.create({ name: "Some Folder", type: "Item" }), -); -expectType[]>>(foundry.documents.BaseFolder.createDocuments([])); -expectType>(foundry.documents.BaseFolder.updateDocuments([])); -expectType>(foundry.documents.BaseFolder.deleteDocuments([])); - -const folder = await foundry.documents.BaseFolder.create( - { name: "Another Folder", type: "Actor" }, - { temporary: true }, -); -if (folder) { - expectType(folder.data); -} diff --git a/test-d/foundry/common/documents.mjs/baseItem.test-d.ts b/test-d/foundry/common/documents.mjs/baseItem.test-d.ts deleted file mode 100644 index 8adb1feb9..000000000 --- a/test-d/foundry/common/documents.mjs/baseItem.test-d.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { expectError, expectType } from "tsd"; - -import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs"; -import type { BaseItem } from "../../../../src/foundry/common/documents.mjs"; -import type { ActiveEffectDataSource } from "../../../../src/foundry/common/data/data.mjs/activeEffectData"; -import type { EffectDurationDataProperties } from "../../../../src/foundry/common/data/data.mjs/effectDurationData"; - -const baseItem = new foundry.documents.BaseItem(); -expectType>(baseItem.effects); -expectType(baseItem.data._source.effects[0]); -expectType(baseItem.data._source.effects[0].duration); - -interface ArmorDataSourceData { - armorValue: number; -} - -interface ArmorDataSource { - type: "armor"; - data: ArmorDataSourceData; -} - -interface WeaponDataSourceData { - damagePerHit: number; - attackSpeed: number; -} - -interface WeaponDataSource { - type: "weapon"; - data: WeaponDataSourceData; -} - -interface ArmorDataPropertiesData extends ArmorDataSourceData { - weight: number; -} - -interface ArmorDataProperties { - type: "armor"; - data: ArmorDataPropertiesData; -} - -interface WeaponDataPropertiesData extends WeaponDataSourceData { - damage: number; -} - -interface WeaponDataProperties { - type: "weapon"; - data: WeaponDataPropertiesData; -} - -type MyItemDataSource = ArmorDataSource | WeaponDataSource; -type MyItemDataProperties = ArmorDataProperties | WeaponDataProperties; - -declare global { - interface DataConfig { - Item: MyItemDataProperties; - } - - interface SourceConfig { - Item: MyItemDataSource; - } -} - -expectType<"weapon" | "armor">(baseItem.data.type); -expectType(baseItem.parent?.items.get("", { strict: true })); - -if (baseItem.data._source.type === "armor") { - expectType(baseItem.data._source.data.armorValue); - expectError(baseItem.data._source.data.weight); -} else { - expectType(baseItem.data._source.data.attackSpeed); - expectType(baseItem.data._source.data.damagePerHit); - expectError(baseItem.data._source.data.damage); -} - -if (baseItem.data.type === "armor") { - expectType(baseItem.data.data.armorValue); - expectType(baseItem.data.data.weight); -} else { - expectType(baseItem.data.data.attackSpeed); - expectType(baseItem.data.data.damagePerHit); - expectType(baseItem.data.data.damage); -} - -// Flags for Actor, Item, Card, and Cards documents can be configured via the FlagConfig. This is tested here. -// For configuring flags for actors and items via SourceConfig please have a look into baseActor.test-d.ts. -declare global { - interface FlagConfig { - Item: { - "my-system": { - countable: boolean; - }; - }; - } -} -expectType<{ countable: boolean }>(baseItem.data.flags["my-system"]); - -expectType(baseItem.getFlag("my-system", "countable")); -expectType(baseItem.getFlag("my-system", "unknown-key")); -expectType(baseItem.getFlag("another-system", "value")); - -expectType>(baseItem.setFlag("my-system", "countable", true)); -expectError(baseItem.setFlag("my-system", "countable", 2)); -expectError(baseItem.setFlag("my-system", "unknown-key", 2)); -expectType>(baseItem.setFlag("another-system", "value", true)); diff --git a/test-d/foundry/common/documents.mjs/baseJournalEntry.test-d.ts b/test-d/foundry/common/documents.mjs/baseJournalEntry.test-d.ts deleted file mode 100644 index 1a6c10dc2..000000000 --- a/test-d/foundry/common/documents.mjs/baseJournalEntry.test-d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>( - foundry.documents.BaseJournalEntry.create({ name: "Some JournalEntry" }), -); -expectType[]>>(foundry.documents.BaseJournalEntry.createDocuments([])); -expectType>(foundry.documents.BaseJournalEntry.updateDocuments([])); -expectType>(foundry.documents.BaseJournalEntry.deleteDocuments([])); - -const journalEntry = await foundry.documents.BaseJournalEntry.create( - { name: "Another JournalEntry" }, - { temporary: true }, -); -if (journalEntry) { - expectType(journalEntry.data); -} diff --git a/test-d/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts b/test-d/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts deleted file mode 100644 index 6c8bffc97..000000000 --- a/test-d/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { expectType } from "tsd"; - -const template = new foundry.documents.BaseMeasuredTemplate(); -expectType(template.data._id); -expectType<"circle" | "cone" | "rect" | "ray">(template.data.t); -expectType(template.parent); diff --git a/test-d/foundry/common/documents.mjs/baseScene.test-d.ts b/test-d/foundry/common/documents.mjs/baseScene.test-d.ts deleted file mode 100644 index 26dea89fa..000000000 --- a/test-d/foundry/common/documents.mjs/baseScene.test-d.ts +++ /dev/null @@ -1,79 +0,0 @@ -import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs"; - -import { expectError, expectType } from "tsd"; - -expectType<{ - distance: number; - height: number; - paddingX: number; - paddingY: number; - ratio: number; - sceneHeight: number; - sceneWidth: number; - shiftX: number; - shiftY: number; - size: number; - width: number; -}>(foundry.documents.BaseScene.getDimensions()); - -expectType<{ - distance: number; - height: number; - paddingX: number; - paddingY: number; - ratio: number; - sceneHeight: number; - sceneWidth: number; - shiftX: number; - shiftY: number; - size: number; - width: number; -}>(foundry.documents.BaseScene.getDimensions({})); - -expectType<{ - distance: number; - height: number; - paddingX: number; - paddingY: number; - ratio: number; - sceneHeight: number; - sceneWidth: number; - shiftX: number; - shiftY: number; - size: number; - width: number; -}>( - foundry.documents.BaseScene.getDimensions({ - width: 100, - height: 200, - gridDistance: 100, - padding: 10, - shiftX: 0, - shiftY: 0, - }), -); - -expectError(foundry.documents.BaseScene.create()); - -expectError(foundry.documents.BaseScene.create({})); - -expectType | undefined>>(foundry.documents.BaseScene.create({ name: "My scene" })); - -const myScene = await foundry.documents.BaseScene.create({ name: "My second scene" }, { temporary: true }); -if (myScene) { - expectType(myScene.data); -} - -expectError(new foundry.documents.BaseScene({})); - -const scene = new foundry.documents.BaseScene({ name: "My third scene" }); -expectType(scene); - -expectType>(scene.drawings); -expectType>(scene.lights); -expectType>(scene.notes); -expectType>(scene.sounds); -expectType>(scene.templates); -expectType>(scene.tokens); -expectType>(scene.tiles); -expectType>(scene.walls); diff --git a/test-d/foundry/common/documents.mjs/baseSetting.test-d.ts b/test-d/foundry/common/documents.mjs/baseSetting.test-d.ts deleted file mode 100644 index 50c70cdf8..000000000 --- a/test-d/foundry/common/documents.mjs/baseSetting.test-d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { expectType } from "tsd"; - -expectType | undefined>>( - foundry.documents.BaseSetting.create({ key: "foo.bar", value: "bar" }), -); -expectType[]>>(foundry.documents.BaseSetting.createDocuments([])); -expectType>(foundry.documents.BaseSetting.updateDocuments([])); -expectType>(foundry.documents.BaseSetting.deleteDocuments([])); - -const settingData = await foundry.documents.BaseSetting.create( - { key: "fizz.buzz", value: "buzz" }, - { temporary: true }, -); -if (settingData) { - expectType(settingData.data); -} diff --git a/test-d/foundry/common/documents.mjs/baseUser.test-d.ts b/test-d/foundry/common/documents.mjs/baseUser.test-d.ts deleted file mode 100644 index c9d957d49..000000000 --- a/test-d/foundry/common/documents.mjs/baseUser.test-d.ts +++ /dev/null @@ -1,92 +0,0 @@ -import type { ConfiguredDocumentClass } from "../../../../src/types/helperTypes"; -import { expectError, expectType } from "tsd"; - -expectType | undefined>>(foundry.documents.BaseUser.create({ name: "SomeUser" })); -expectType[]>>(foundry.documents.BaseUser.createDocuments([])); -expectType>[]>>( - foundry.documents.BaseUser.updateDocuments([]), -); -expectType>[]>>( - foundry.documents.BaseUser.deleteDocuments([]), -); - -const user = await foundry.documents.BaseUser.create({ name: "Another User" }, { temporary: true }); -if (user) { - expectType(user.data); -} - -const baseUser = new foundry.documents.BaseUser(); -expectType(baseUser.hasRole("NONE")); -expectType(baseUser.hasRole("PLAYER")); -expectType(baseUser.hasRole("TRUSTED")); -expectType(baseUser.hasRole("ASSISTANT")); -expectType(baseUser.hasRole("GAMEMASTER")); - -expectType(baseUser.hasRole(CONST.USER_ROLES.NONE)); -expectType(baseUser.hasRole(CONST.USER_ROLES.PLAYER)); -expectType(baseUser.hasRole(CONST.USER_ROLES.TRUSTED)); -expectType(baseUser.hasRole(CONST.USER_ROLES.ASSISTANT)); -expectType(baseUser.hasRole(CONST.USER_ROLES.GAMEMASTER)); - -expectError(baseUser.hasRole("ACTOR_CREATE")); -expectError(baseUser.hasRole(-1)); -expectError(baseUser.hasRole(100)); - -expectType(baseUser.can("NONE")); -expectType(baseUser.can("PLAYER")); -expectType(baseUser.can("TRUSTED")); -expectType(baseUser.can("ASSISTANT")); -expectType(baseUser.can("GAMEMASTER")); - -expectType(baseUser.can(CONST.USER_ROLES.NONE)); -expectType(baseUser.can(CONST.USER_ROLES.PLAYER)); -expectType(baseUser.can(CONST.USER_ROLES.TRUSTED)); -expectType(baseUser.can(CONST.USER_ROLES.ASSISTANT)); -expectType(baseUser.can(CONST.USER_ROLES.GAMEMASTER)); - -expectType(baseUser.can("ACTOR_CREATE")); -expectType(baseUser.can("BROADCAST_AUDIO")); -expectType(baseUser.can("BROADCAST_VIDEO")); -expectType(baseUser.can("DRAWING_CREATE")); -expectType(baseUser.can("ITEM_CREATE")); -expectType(baseUser.can("FILES_BROWSE")); -expectType(baseUser.can("FILES_UPLOAD")); -expectType(baseUser.can("JOURNAL_CREATE")); -expectType(baseUser.can("MACRO_SCRIPT")); -expectType(baseUser.can("MESSAGE_WHISPER")); -expectType(baseUser.can("NOTE_CREATE")); -expectType(baseUser.can("SETTINGS_MODIFY")); -expectType(baseUser.can("SHOW_CURSOR")); -expectType(baseUser.can("SHOW_RULER")); -expectType(baseUser.can("TEMPLATE_CREATE")); -expectType(baseUser.can("TOKEN_CREATE")); -expectType(baseUser.can("TOKEN_CONFIGURE")); -expectType(baseUser.can("WALL_DOORS")); - -expectError(baseUser.can(-1)); -expectError(baseUser.can(100)); -expectError(baseUser.can("SHOW_RULERS")); - -expectType(baseUser.hasPermission("ACTOR_CREATE")); -expectType(baseUser.hasPermission("BROADCAST_AUDIO")); -expectType(baseUser.hasPermission("BROADCAST_VIDEO")); -expectType(baseUser.hasPermission("DRAWING_CREATE")); -expectType(baseUser.hasPermission("ITEM_CREATE")); -expectType(baseUser.hasPermission("FILES_BROWSE")); -expectType(baseUser.hasPermission("FILES_UPLOAD")); -expectType(baseUser.hasPermission("JOURNAL_CREATE")); -expectType(baseUser.hasPermission("MACRO_SCRIPT")); -expectType(baseUser.hasPermission("MESSAGE_WHISPER")); -expectType(baseUser.hasPermission("NOTE_CREATE")); -expectType(baseUser.hasPermission("SETTINGS_MODIFY")); -expectType(baseUser.hasPermission("SHOW_CURSOR")); -expectType(baseUser.hasPermission("SHOW_RULER")); -expectType(baseUser.hasPermission("TEMPLATE_CREATE")); -expectType(baseUser.hasPermission("TOKEN_CREATE")); -expectType(baseUser.hasPermission("TOKEN_CONFIGURE")); -expectType(baseUser.hasPermission("WALL_DOORS")); - -expectError(baseUser.hasPermission("GAMEMASTER")); -expectError(baseUser.hasPermission(CONST.USER_ROLES.GAMEMASTER)); -expectError(baseUser.hasPermission(10)); -expectError(baseUser.hasPermission("SHOW_RULERS")); diff --git a/test-d/foundry/common/documents.mjs/baseWall.test-d.ts b/test-d/foundry/common/documents.mjs/baseWall.test-d.ts deleted file mode 100644 index 429d843d2..000000000 --- a/test-d/foundry/common/documents.mjs/baseWall.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectError } from "tsd"; - -declare const scene: Scene; - -expectError(new foundry.documents.BaseWall()); -expectError(new foundry.documents.BaseWall({})); - -new foundry.documents.BaseWall({ c: [0, 0, 0, 0] }); -new foundry.documents.BaseWall({ c: [0, 0, 0, 0] }, { parent: scene }); diff --git a/test-d/foundry/common/primitives/array.mjs.test-d.ts b/test-d/foundry/common/primitives/array.mjs.test-d.ts deleted file mode 100644 index 2a7a53b2e..000000000 --- a/test-d/foundry/common/primitives/array.mjs.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; -import "../../index"; - -expectType([["testing"], "test"].deepFlatten()); - -expectType<["a"[], "b"[]]>(Array<"a" | "b">().partition((val): val is "b" => val === "b")); -expectType<[number[], string[]]>([1, ""].partition((val): val is string => typeof val === "string")); -expectType<[string[], string[]]>(Array().partition((val): boolean => val.length < 5)); -expectType<[string[], string[]]>(Array().partition((val) => val.length < 5)); diff --git a/test-d/foundry/common/primitives/set.mjs.test-d.ts b/test-d/foundry/common/primitives/set.mjs.test-d.ts deleted file mode 100644 index 2b1fda8ee..000000000 --- a/test-d/foundry/common/primitives/set.mjs.test-d.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { expectType } from "tsd"; -import "../../index"; - -expectType>(new Set().filter((value): value is string => typeof value === "string")); -expectType>(new Set<"a" | "b">().filter((value): value is "a" => value === "a")); - -expectType(new Set().find((value) => value > 5)); -expectType(new Set().find((value): value is number => typeof value === "number")); -expectType<"a" | undefined>(new Set<"a" | "b">().find((value): value is "a" => value === "a")); diff --git a/test-d/foundry/common/primitives/string.mjs.test-d.ts b/test-d/foundry/common/primitives/string.mjs.test-d.ts deleted file mode 100644 index fbb7bebf4..000000000 --- a/test-d/foundry/common/primitives/string.mjs.test-d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { expectType } from "tsd"; -import "../../index"; - -expectType<"Foo">("foo".capitalize()); -expectType<"FOO">("FOO".capitalize()); -expectType<"Foo bar">("foo bar".capitalize()); -expectType<"FOO BAR">("FOO BAR".capitalize()); - -expectType<"Foo">("foo".titleCase()); -expectType<"Foo">("FOO".titleCase()); -expectType<"Foo Bar">("foo bar".titleCase()); -expectType<"Foo Bar">("FOO BAR".titleCase()); diff --git a/test-d/foundry/common/utils/collection.mjs.test-d.ts b/test-d/foundry/common/utils/collection.mjs.test-d.ts deleted file mode 100644 index 040fd82ae..000000000 --- a/test-d/foundry/common/utils/collection.mjs.test-d.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { expectType } from "tsd"; -import "../../../index"; - -const c = new Collection(); - -expectType(c.get("")); -expectType(c.get("", { strict: false })); -expectType(c.get("", { strict: true })); - -expectType(c.getName("")); -expectType(c.getName("", { strict: false })); -expectType(c.getName("", { strict: true })); - -function isString(e: string | null): e is string { - return typeof e === "string"; -} - -const cn = new Collection(); -expectType>(cn.filter((each) => typeof each === "string")); -expectType(cn.find((each) => typeof each === "string")); - -expectType(cn.filter(isString)); -expectType(cn.find(isString)); diff --git a/test-d/foundry/common/utils/helpers.mjs.test-d.ts b/test-d/foundry/common/utils/helpers.mjs.test-d.ts deleted file mode 100644 index d5e0aa1df..000000000 --- a/test-d/foundry/common/utils/helpers.mjs.test-d.ts +++ /dev/null @@ -1,407 +0,0 @@ -import { expectAssignable, expectError, expectNotAssignable, expectType } from "tsd"; -import "../../../index"; - -// benchmark - -declare function functionWithoutParameters(): void; -declare function functionWithParameters(a: number, b: string, c?: boolean): void; -declare function functionWithReturnTypeOtherThanVoid(): number; - -expectType>(foundry.utils.benchmark(functionWithoutParameters, 42)); -expectError(foundry.utils.benchmark(functionWithoutParameters, 42, "unknown argument")); -expectType>(foundry.utils.benchmark(functionWithParameters, 42, 1, "", false)); -expectType>(foundry.utils.benchmark(functionWithParameters, 42, 1, "")); -expectError(foundry.utils.benchmark(functionWithParameters, 42, 1)); -expectError(foundry.utils.benchmark(functionWithParameters, 42, 1, "", "unknown argument")); -expectType>(foundry.utils.benchmark(functionWithReturnTypeOtherThanVoid, 42)); - -// deepClone - -const complexObject = { - a: "", - b: 0, - toJSON: () => [ - false, - undefined, - { - c: undefined, - d: ((): boolean | symbol => false)(), - e: [true], - f: { g: 0, h: ((): number | undefined => 0)() }, - }, - ], -}; - -expectType(foundry.utils.deepClone("abc" as string)); -expectType<"abc">(foundry.utils.deepClone("abc")); -expectType(foundry.utils.deepClone(1 as number)); -expectType<1>(foundry.utils.deepClone(1)); -expectType(foundry.utils.deepClone(1n as bigint)); -expectType<1n>(foundry.utils.deepClone(1n)); -expectType(foundry.utils.deepClone(true)); -expectType(foundry.utils.deepClone(true as boolean)); -expectType(foundry.utils.deepClone(Symbol("customSymbol"))); -expectType(foundry.utils.deepClone(undefined)); -expectType(foundry.utils.deepClone(null)); -expectType>(foundry.utils.deepClone(["a", "b"])); -expectType>(foundry.utils.deepClone(["a", "b"])); -expectType<{ a: string; b: number }>(foundry.utils.deepClone({ a: "foo", b: 42 })); -expectType(foundry.utils.deepClone(new Date())); -expectType(foundry.utils.deepClone(complexObject)); - -expectType(foundry.utils.deepClone("abc" as string, { strict: false })); -expectType(foundry.utils.deepClone("abc" as string, { strict: true })); -expectType(foundry.utils.deepClone("abc" as string, { strict: true as boolean })); - -// duplicate - -expectType(foundry.utils.duplicate("")); - -expectType(foundry.utils.duplicate(0)); - -expectType<0 | 1>(foundry.utils.duplicate<0 | 1>(0)); - -expectType<"foo" | "bar">(foundry.utils.duplicate<"foo" | "bar">("foo")); - -expectType(foundry.utils.duplicate(0)); - -/* `NaN` will actually be converted to `null` but for ease of use, this is ignored. */ -expectType(foundry.utils.duplicate(NaN)); - -expectType(foundry.utils.duplicate(((): boolean => false)())); - -expectType(foundry.utils.duplicate(null)); - -expectType(foundry.utils.duplicate(undefined)); - -expectType(foundry.utils.duplicate(() => 0)); - -expectType(foundry.utils.duplicate(Symbol(""))); - -expectType(foundry.utils.duplicate(false)); - -expectType(foundry.utils.duplicate(((): string | boolean => "")())); - -expectType(foundry.utils.duplicate(((): string | number => "")())); - -expectType(foundry.utils.duplicate(((): string | null => "")())); - -expectType(foundry.utils.duplicate(((): string | undefined => "")())); - -expectType(foundry.utils.duplicate(((): string | Function => "")())); - -expectType(foundry.utils.duplicate(((): string | symbol => "")())); - -expectType>(foundry.utils.duplicate([""])); - -expectType>(foundry.utils.duplicate([0])); - -expectType>(foundry.utils.duplicate([false, true])); - -expectType>(foundry.utils.duplicate([null])); - -expectType>(foundry.utils.duplicate([undefined])); - -expectType>(foundry.utils.duplicate([() => 0])); - -expectType>(foundry.utils.duplicate([Symbol("")])); - -expectType>(foundry.utils.duplicate([false])); - -expectType>(foundry.utils.duplicate(["", false, true])); - -expectType>(foundry.utils.duplicate(["", 0])); - -expectType>(foundry.utils.duplicate(["", null])); - -expectType>(foundry.utils.duplicate(["", undefined])); - -expectType>(foundry.utils.duplicate(["", () => 0])); - -expectType>(foundry.utils.duplicate(["", Symbol("")])); - -expectType>(foundry.utils.duplicate([((): "a" | "b" => "a")()])); - -expectType>>(foundry.utils.duplicate([[false, true]])); - -expectType>(foundry.utils.duplicate([{ a: "" }])); - -expectType<{ a: string }>(foundry.utils.duplicate({ a: "" })); - -expectType<{ a: number }>(foundry.utils.duplicate({ a: 0 })); - -expectType<{ a: boolean }>(foundry.utils.duplicate({ a: ((): boolean => false)() })); - -expectType<{ a: null }>(foundry.utils.duplicate({ a: null })); - -expectType<{}>(foundry.utils.duplicate({ a: undefined })); - -expectType<{}>(foundry.utils.duplicate({ a: () => 0 })); - -expectType<{}>(foundry.utils.duplicate({ a: Symbol("") })); - -expectType<{ a: string | boolean }>(foundry.utils.duplicate({ a: ((): string | boolean => "")() })); - -expectType<{ a: string | number }>(foundry.utils.duplicate({ a: ((): string | number => "")() })); - -expectType<{ a: string | null }>(foundry.utils.duplicate({ a: ((): string | null => "")() })); - -expectType<{ a?: string | undefined }>(foundry.utils.duplicate({ a: ((): string | undefined => "")() })); - -expectType<{ a?: string | undefined }>(foundry.utils.duplicate({ a: ((): string | Function => "")() })); - -expectType<{ a?: string | undefined }>(foundry.utils.duplicate({ a: ((): string | symbol => "")() })); - -expectType<{ a: Array }>(foundry.utils.duplicate({ a: [""] })); - -expectType<{ a: { b: string } }>(foundry.utils.duplicate({ a: { b: "" } })); - -expectType<{ a: false }>(foundry.utils.duplicate({ a: false })); - -expectType<{ a: "a" | "b" }>(foundry.utils.duplicate({ a: ((): "a" | "b" => "a")() })); - -expectType(foundry.utils.duplicate({ a: 0, b: "", c: false, toJSON: (): string => "" })); - -expectType<{ foo: string; bar: boolean }>( - foundry.utils.duplicate({ a: 0, b: "", c: false, toJSON: () => ({ foo: "", bar: ((): boolean => false)() }) }), -); - -expectType<{ foo: string; bar: boolean }>( - foundry.utils.duplicate({ - a: 0, - b: "", - c: false, - toJSON: () => ({ foo: "", bar: ((): boolean => false)(), toJSON: () => "" }), - }), -); - -expectType<{ foo: string; bar: false }>( - foundry.utils.duplicate({ - a: 0, - b: "", - c: false, - toJSON: () => ({ foo: "", bar: { baz: "", toJSON: () => false } }), - }), -); - -expectType< - Array< - | boolean - | null - | { - d?: boolean | undefined; - e: Array; - f: { g: number; h?: number | undefined }; - } - > ->(foundry.utils.duplicate(complexObject)); - -// isSubclass - -declare class ClassWithNoConstructorParameters {} - -declare class ClassWithConstructorParameters { - constructor(a: number, b: string); -} - -expectType(foundry.utils.isSubclass(ClassWithNoConstructorParameters, ClassWithConstructorParameters)); -expectType(foundry.utils.isSubclass(ClassWithConstructorParameters, ClassWithNoConstructorParameters)); - -// invertObject -expectType<{ readonly 1: "a"; readonly foo: "b" }>(foundry.utils.invertObject({ a: 1, b: "foo" } as const)); - -// mergeObject: expectAssignable is used here because of https://github.com/SamVerschueren/tsd/issues/67 -// mergeObject (1): tests from the docs -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "v1" }, { k2: "v2" }, { insertKeys: false })); -expectAssignable<{ k1: string; k2: string }>( - foundry.utils.mergeObject({ k1: "v1" }, { k2: "v2" }, { insertKeys: true }), -); -expectAssignable<{ k1: { i1: string } }>( - foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { insertValues: false }), -); -expectAssignable<{ k1: { i1: string; i2: string } }>( - foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { insertValues: true }), -); - -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "v1" }, { k1: "v2" }, { overwrite: true })); -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "v1" }, { k1: "v2" }, { overwrite: false })); - -expectAssignable<{ k1: { i2: string } }>( - foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { recursive: false }), -); -expectAssignable<{ k1: { i1: string; i2: string } }>( - foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { recursive: true }), -); - -// mergeObject (2): more simple tests - -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" })); -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" }, {})); -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" }, { insertKeys: false })); -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" }, { insertKeys: true })); - -expectAssignable<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" })); -expectAssignable<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" }, {})); -expectAssignable<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" }, { insertKeys: false })); -expectAssignable<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" }, { insertKeys: true })); - -expectAssignable<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" })); -expectAssignable<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, {})); -expectAssignable<{ k1: number }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { insertKeys: false })); -expectAssignable<{ k1: number; k2: string }>( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { insertKeys: true }), -); - -expectAssignable(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: true })); -expectAssignable<{ k1: number; k2: string }>( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: false }), -); -expectAssignable( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: true, insertKeys: false }), -); -expectAssignable( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: true, insertKeys: true }), -); - -expectAssignable<{ k1: string; k2: string }>( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: false }), -); -expectAssignable<{ k1: number; k2: string }>( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: true }), -); -expectAssignable<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, {})); -expectAssignable<{ k1: string }>( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: false, insertKeys: false }), -); -expectAssignable<{ k1: string; k2: string }>( - foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: false, insertKeys: true }), -); - -// mergeObject (3): more complex examples -expectAssignable<{ k1: { i1: string; i2: string }; k2: number; k3: number }>( - foundry.utils.mergeObject({ k1: { i1: "foo" }, k2: 2 }, { k1: { i2: "bar" }, k3: 3 }), -); -expectAssignable<{ k1: { i1: string; i2: string; i3: number }; k2: number; k3: number }>( - foundry.utils.mergeObject({ k1: { i1: "foo", i3: { j1: 0 } }, k2: 2 }, { k1: { i2: "bar", i3: 2 }, k3: 3 }), -); -expectAssignable<{ k1: { i2: string; i3: number }; k2: number; k3: number }>( - foundry.utils.mergeObject( - { k1: { i1: "foo", i3: { j1: 0 } }, k2: 2 }, - { k1: { i2: "bar", i3: 2 }, k3: 3 }, - { recursive: false }, - ), -); -expectType<{ i2: string; i3: number }>( - foundry.utils.mergeObject( - { k1: { i1: "foo", i3: { j1: 0 } }, k2: 2 }, - { k1: { i2: "bar", i3: 2 }, k3: 3 }, - { recursive: false }, - ).k1, -); -expectAssignable<{ - k1: { i1: string; i2: string; i3: { j1: string; j2: number; j3: string } }; - k2: number; - k3: number; -}>( - foundry.utils.mergeObject( - { k1: { i1: "foo", i3: { j1: 1, j2: 2 } }, k2: 2 }, - { k1: { i2: "bar", i3: { j1: "1", j3: "3" } }, k3: 3 }, - ), -); -expectAssignable<{ k1: { i1: string; i3: { j1: string; j2: number } }; k2: number; k3: number }>( - foundry.utils.mergeObject( - { k1: { i1: "foo", i3: { j1: 1, j2: 2 } }, k2: 2 }, - { k1: { i2: "bar", i3: { j1: "1", j3: "3" } }, k3: 3 }, - { insertValues: false }, - ), -); -expectAssignable<{ k1: { i2: string; i3: { j1: string; j3: string } }; k2: number; k3: number }>( - foundry.utils.mergeObject( - { k1: { i1: "foo", i3: { j1: 1, j2: 2 } }, k2: 2 }, - { k1: { i2: "bar", i3: { j1: "1", j3: "3" } }, k3: 3 }, - { recursive: false }, - ), -); - -// Array merging - -expectAssignable( - foundry.utils.mergeObject(FormApplication.defaultOptions, { - classes: ["my", "custom", "css"], - }), -); -expectAssignable<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] })); -expectAssignable<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertKeys: true })); -expectAssignable<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertValues: true })); -expectAssignable<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertKeys: false })); -expectAssignable<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertValues: false })); -expectAssignable<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { enforceTypes: true })); -expectAssignable(foundry.utils.mergeObject({ a: ["foo"] }, { a: { b: "foo" } }, { enforceTypes: true })); -expectAssignable<{ a: { b: string } }>( - foundry.utils.mergeObject({ a: ["foo"] }, { a: { b: "foo" } }, { enforceTypes: false }), -); -expectAssignable(foundry.utils.mergeObject({ a: { b: "foo" } }, { a: ["foo"] }, { enforceTypes: true })); -expectAssignable<{ a: string[] }>( - foundry.utils.mergeObject({ a: { b: "foo" } }, { a: ["foo"] }, { enforceTypes: false }), -); - -// performDeletions -// v10, `-=` prefixed keys are no longer auto removed -expectAssignable<{ k1: string; k2: string; "-=k1": null }>( - foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }), -); -expectAssignable<{ k1: string; k2: string; "-=k1": null }>( - foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: false }), -); -expectAssignable<{ k2: string; "-=k1": null }>(foundry.utils.mergeObject({ k2: "v2" }, { "-=k1": null })); -expectAssignable<{ k1: string; k2: string; "-=k1": null }>( - foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }), -); - -expectAssignable<{ k2: string }>( - foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), -); -expectNotAssignable<{ k1: string; k2: string; "-=k1": null }>( - foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), -); -expectNotAssignable<{ k2: string; "-=k1": null }>( - foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), -); -expectNotAssignable<{ k1: string; k2: string }>( - foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), -); - -expectAssignable<{ k2: string }>(foundry.utils.mergeObject({ k2: "v2" }, { "-=k1": null }, { insertKeys: false })); -expectNotAssignable<{ k2: string; "-=k1": null }>( - foundry.utils.mergeObject({ k2: "v2" }, { "-=k1": null }, { insertKeys: false }), -); - -expectAssignable<{ wrapper: { k2: string } }>( - foundry.utils.mergeObject( - { wrapper: { k1: "v1", k2: "v2" } }, - { wrapper: { "-=k1": null } }, - { recursive: true, performDeletions: true }, - ), -); -expectAssignable<{ wrapper: { k1: string; k2: string; "-=k1": null } }>( - foundry.utils.mergeObject({ wrapper: { k1: "v1", k2: "v2" } }, { wrapper: { "-=k1": null } }, { recursive: true }), -); - -// bonus round -expectAssignable<{ a: number; b: number }>(foundry.utils.mergeObject({ a: 1 }, { b: 2 }, { enforceTypes: true })); -expectNotAssignable(foundry.utils.mergeObject({ a: 1 }, { b: 2 }, { enforceTypes: true })); - -expectAssignable<{ a: { a: number; b: number } }>( - foundry.utils.mergeObject({ a: { a: 1 } }, { a: { b: 2 } }, { enforceTypes: true }), -); -expectNotAssignable(foundry.utils.mergeObject({ a: { a: 1 } }, { b: { a: 2 } }, { enforceTypes: true })); - -expectAssignable<{ a: { a: number }; b: { a: number }; c: number }>( - foundry.utils.mergeObject({ a: { a: 1 }, c: 1 }, { b: { a: 2 }, c: 1 }, { enforceTypes: true }), -); -expectNotAssignable( - foundry.utils.mergeObject({ a: { a: 1 }, c: 1 }, { b: { a: 2 }, c: 1 }, { enforceTypes: true }), -); - -expectError(foundry.utils.mergeObject(1, 2)); -expectError(foundry.utils.mergeObject("foo", "bar")); diff --git a/test-d/foundry/common/utils/http.mjs.test-d.ts b/test-d/foundry/common/utils/http.mjs.test-d.ts deleted file mode 100644 index 46fe9db54..000000000 --- a/test-d/foundry/common/utils/http.mjs.test-d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { expectType } from "tsd"; - -expectType>(foundry.utils.fetchWithTimeout("/")); -expectType>(foundry.utils.fetchJsonWithTimeout("/")); diff --git a/test-d/foundry/common/utils/semaphore.mjs.test-d.ts b/test-d/foundry/common/utils/semaphore.mjs.test-d.ts deleted file mode 100644 index 62fb3d25d..000000000 --- a/test-d/foundry/common/utils/semaphore.mjs.test-d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { expectError, expectType } from "tsd"; -import "../../index"; - -declare const lock: Semaphore; - -expectType>(lock.add(async (s: string) => !s, "test")); -expectType>(lock.add(async () => false)); - -expectError(lock.add(async (s: string) => !s)); -expectError(lock.add(async () => false, "")); diff --git a/test-d/foundry/prosemirror/prosemirror.test-d.ts b/test-d/foundry/prosemirror/prosemirror.test-d.ts deleted file mode 100644 index 9c3e49e8f..000000000 --- a/test-d/foundry/prosemirror/prosemirror.test-d.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Schema } from "prosemirror-model"; -import type { EditorState } from "prosemirror-state"; -import { expectType } from "tsd"; - -expectType(ProseMirror.EditorState); -expectType(ProseMirror.Schema); -expectType(ProseMirror.defaultSchema); diff --git a/test-d/tsconfig.json b/test-d/tsconfig.json deleted file mode 100644 index 395611a21..000000000 --- a/test-d/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../tsconfig.json", - "compilerOptions": { - "module": "esnext" - }, - "include": ["../index.d.ts", "../index-lenient.d.ts", "./foundry", "./types", "./custom"] -} diff --git a/test-d/types/utils.test-d.ts b/test-d/types/utils.test-d.ts deleted file mode 100644 index 38129a669..000000000 --- a/test-d/types/utils.test-d.ts +++ /dev/null @@ -1,100 +0,0 @@ -import { expectAssignable, expectType } from "tsd"; -import "../../index"; - -const membersBecomeOptional: DeepPartial<{ a: string }> = {}; -expectType<{ a?: string }>(membersBecomeOptional); - -const nestedMembersBecomeOptional: DeepPartial<{ a: { b: string } }> = { a: {} }; -expectType<{ a?: { b?: string } }>(nestedMembersBecomeOptional); - -const expanded1: Expanded<{ foo: string }> = { foo: "" }; -expectType<{ foo: string }>(expanded1); -const expanded2: Expanded<{ "foo.bar": string }> = { foo: { bar: "" } }; -expectType<{ foo: { bar: string } }>(expanded2); -const expanded3: Expanded<{ "foo.bar": string[] }> = { foo: { bar: [""] } }; -expectType<{ foo: { bar: string[] } }>(expanded3); -const expanded4: Expanded<{ foo: { "bar.baz": string } }> = { foo: { bar: { baz: "" } } }; -expectType<{ foo: { bar: { baz: string } } }>(expanded4); -const expanded5: Expanded<{ "foo.bar": string; "baz.qux": string }> = { foo: { bar: "" }, baz: { qux: "" } }; -expectType<{ foo: { bar: string }; baz: { qux: string } }>(expanded5); -const expanded6: Expanded<{ "foo.bar": string; baz: { qux: string } }> = { foo: { bar: "" }, baz: { qux: "" } }; -expectType<{ foo: { bar: string }; baz: { qux: string } }>(expanded6); -const expanded7: Expanded<{ "foo.bar": string | number }> = { foo: { bar: 0 } }; -expectType<{ foo: { bar: string | number } }>(expanded7); -const expanded8: Expanded<{ foo: { bar: string } | { baz: number } }> = { foo: { bar: "" } }; -expectType<{ foo: { bar: string } | { baz: number } }>(expanded8); -const expanded9: Expanded<{ "foo.bar"?: string }> = {}; -expectType<{ foo?: { bar: string | undefined } }>(expanded9); - -declare const titlecaseEmpty: Titlecase<"">; -expectType<"">(titlecaseEmpty); -declare const titlecaseBlank: Titlecase<" ">; -expectType<" ">(titlecaseBlank); -declare const titlecaseNumber: Titlecase<"42">; -expectType<"42">(titlecaseNumber); -declare const titlecaseFromLower: Titlecase<"foobar">; -expectType<"Foobar">(titlecaseFromLower); -declare const titlecaseFromUpper: Titlecase<"FOOBAR">; -expectType<"Foobar">(titlecaseFromUpper); -declare const titlecaseWithSpace: Titlecase<"foo bar">; -expectType<"Foo Bar">(titlecaseWithSpace); -declare const titlecaseWithSpaces: Titlecase<"foo bar">; -expectType<"Foo Bar">(titlecaseWithSpaces); -declare const titlecaseWithThreeWords: Titlecase<"foo bar baz">; -expectType<"Foo Bar Baz">(titlecaseWithThreeWords); - -const numberMaybePromise: MaybePromise = 0; -expectType(await numberMaybePromise); - -declare const user: User; -expectType(user.id); -expectType(user.data._id); -expectType(user.data._source._id); -expectType(user.toJSON()._id); -expectType(user.data.toJSON()._id); -expectType(user.toObject()._id); -expectType(user.data.toObject()._id); -expectType(user.toObject(false)._id); -expectType(user.data.toObject(false)._id); -expectType>(user.clone()); - -declare const storedUser: StoredDocument; -expectType(storedUser.id); -expectType(storedUser.data._id); -expectType(storedUser.data._source._id); -expectType(storedUser.toJSON()._id); -expectType(storedUser.data.toJSON()._id); -expectType(storedUser.toObject()._id); -expectType(storedUser.data.toObject()._id); -expectType(storedUser.toObject(false)._id); -expectType(storedUser.data.toObject(false)._id); -expectType>(storedUser.clone()); - -declare const actor: StoredDocument; -expectType(actor.id); -expectType(actor.data._id); -expectType(actor.data._source._id); -expectType(actor.toJSON()._id); -expectType(actor.data.toJSON()._id); -expectType(actor.toObject()._id); -expectType(actor.data.toObject()._id); -expectType(actor.toObject(false)._id); -expectType(actor.data.toObject(false)._id); -expectType>(actor.clone()); - -if (actor.data.type === "character") { - expectType(actor.data.data.health); - expectType(actor.data.data.movement); -} else { - expectType(actor.data.data.faction); - expectType(actor.data.data.challenge); - expectType(actor.data.data.damage); -} - -// we need to test with `expectAssignable` because the types are not considered euqal, even though they are structurally the same -type A = { foo?: string; bar?: number; baz: boolean }; -type B = { foo: string; bar?: number; baz: boolean }; -declare const someVariable: RequiredProps; -declare const someOtherVariable: B; -expectAssignable(someVariable); -expectAssignable>(someOtherVariable); diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 000000000..973b843c4 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +tsconfig.vitest-temp.json diff --git a/test-d/custom/custom-error-hooks.d.ts b/tests/custom/custom-error-hooks.d.ts similarity index 100% rename from test-d/custom/custom-error-hooks.d.ts rename to tests/custom/custom-error-hooks.d.ts diff --git a/test-d/custom/custom-hooks.d.ts b/tests/custom/custom-hooks.d.ts similarity index 100% rename from test-d/custom/custom-hooks.d.ts rename to tests/custom/custom-hooks.d.ts diff --git a/tests/foundry/client/apps/app.test-d.ts b/tests/foundry/client/apps/app.test-d.ts new file mode 100644 index 000000000..faedbeff8 --- /dev/null +++ b/tests/foundry/client/apps/app.test-d.ts @@ -0,0 +1,21 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(Application.defaultOptions).toEqualTypeOf(); + +const app = new (class extends Application {})(); +expectTypeOf(app.id).toEqualTypeOf(); +expectTypeOf(app.element).toEqualTypeOf(); +expectTypeOf(app.appId).toEqualTypeOf(); +expectTypeOf(app.popOut).toEqualTypeOf(); +expectTypeOf(app.template).toEqualTypeOf(); +expectTypeOf(app.title).toEqualTypeOf(); +expectTypeOf(app.rendered).toEqualTypeOf(); + +expectTypeOf(app.bringToTop()).toEqualTypeOf(); +expectTypeOf(app.getData()).toEqualTypeOf>(); +expectTypeOf(app.options).toEqualTypeOf(); +expectTypeOf(app.close({ force: false })).toEqualTypeOf>(); +expectTypeOf(app.close()).toEqualTypeOf>(); +expectTypeOf(app.render()).toEqualTypeOf(); +expectTypeOf(app.render(true)).toEqualTypeOf(); +expectTypeOf(app.render(false, { height: "auto" })).toEqualTypeOf(); diff --git a/test-d/foundry/client/apps/av/av-config.test-d.ts b/tests/foundry/client/apps/av/av-config.test-d.ts similarity index 100% rename from test-d/foundry/client/apps/av/av-config.test-d.ts rename to tests/foundry/client/apps/av/av-config.test-d.ts diff --git a/test-d/foundry/client/apps/form.test-d.ts b/tests/foundry/client/apps/form.test-d.ts similarity index 50% rename from test-d/foundry/client/apps/form.test-d.ts rename to tests/foundry/client/apps/form.test-d.ts index 1a2ffaa67..e43541cab 100644 --- a/test-d/foundry/client/apps/form.test-d.ts +++ b/tests/foundry/client/apps/form.test-d.ts @@ -1,5 +1,5 @@ -import { expectAssignable, expectType } from "tsd"; -import { BaseAmbientLight } from "../../../../src/foundry/common/documents.mjs"; +import { assertType, expectTypeOf } from "vitest"; +import { BaseAmbientLight } from "../../../../src/foundry/common/documents.mjs/index.js"; const app = new (class extends FormApplication { protected _updateObject(): Promise { @@ -7,13 +7,13 @@ const app = new (class extends FormApplication(app); -expectType(app.isEditable); -expectType<{ foo: string }>(app.object); +assertType(app); +expectTypeOf(app.isEditable).toEqualTypeOf(); +expectTypeOf(app.object).toEqualTypeOf<{ foo: string }>(); const doc = new BaseAmbientLight(); const sheet = new (class extends DocumentSheet, BaseAmbientLight> {})(doc); -expectAssignable>(sheet); -expectType(sheet.isEditable); -expectType(sheet.document); +assertType>(sheet); +expectTypeOf(sheet.isEditable).toEqualTypeOf(); +expectTypeOf(sheet.document).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/forms/actor.test-d.ts b/tests/foundry/client/apps/forms/actor.test-d.ts new file mode 100644 index 000000000..d34d88fea --- /dev/null +++ b/tests/foundry/client/apps/forms/actor.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const actorSheet = new ActorSheet(new Actor({ name: "Some dude", type: "character" })); +expectTypeOf(actorSheet.object).toEqualTypeOf(); +expectTypeOf(actorSheet.actor).toEqualTypeOf(); +expectTypeOf(actorSheet.token).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/forms/combatant-config.test-d.ts b/tests/foundry/client/apps/forms/combatant-config.test-d.ts new file mode 100644 index 000000000..0cce5eee0 --- /dev/null +++ b/tests/foundry/client/apps/forms/combatant-config.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +declare const combatant: Combatant; +declare const baseCombatant: foundry.documents.BaseCombatant; + +expectTypeOf(CombatantConfig.defaultOptions).toEqualTypeOf(); + +// @ts-expect-error - a BaseCombatant is not a Combatant +new CombatantConfig(baseCombatant); + +const sheet = new CombatantConfig(combatant); +expectTypeOf(sheet.document).toEqualTypeOf(); +expectTypeOf(sheet.object).toEqualTypeOf(); +expectTypeOf(sheet.title).toEqualTypeOf(); +expectTypeOf(sheet.options).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/forms/effect-config.test-d.ts b/tests/foundry/client/apps/forms/effect-config.test-d.ts new file mode 100644 index 000000000..079e0d4be --- /dev/null +++ b/tests/foundry/client/apps/forms/effect-config.test-d.ts @@ -0,0 +1,13 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - a BaseActiveEffect is not a ActiveEffect +new ActiveEffectConfig(new foundry.documents.BaseActiveEffect()); + +const config = new ActiveEffectConfig(new ActiveEffect()); +expectTypeOf(config.object).toEqualTypeOf(); +expectTypeOf(config.options).toEqualTypeOf>(); + +const withCustomOptions = new ActiveEffectConfig & { custom: true }>( + new ActiveEffect(), +); +expectTypeOf(withCustomOptions.options).toEqualTypeOf & { custom: true }>(); diff --git a/tests/foundry/client/apps/forms/item.test-d.ts b/tests/foundry/client/apps/forms/item.test-d.ts new file mode 100644 index 000000000..0b1f426f3 --- /dev/null +++ b/tests/foundry/client/apps/forms/item.test-d.ts @@ -0,0 +1,5 @@ +import { expectTypeOf } from "vitest"; + +const itemSheet = new ItemSheet(new Item({ name: "Heavy armor", type: "armor" })); +expectTypeOf(itemSheet.object).toEqualTypeOf(); +expectTypeOf(itemSheet.item).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/forms/journal-sheet.test-d.ts b/tests/foundry/client/apps/forms/journal-sheet.test-d.ts new file mode 100644 index 000000000..37b702b4b --- /dev/null +++ b/tests/foundry/client/apps/forms/journal-sheet.test-d.ts @@ -0,0 +1,5 @@ +import { expectTypeOf } from "vitest"; + +const journalSheet = new JournalSheet(new JournalEntry({ name: "Some Journal Entry" })); +expectTypeOf(journalSheet.object).toEqualTypeOf(); +expectTypeOf(journalSheet.render(true, { sheetMode: "image" })).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/forms/macro-config.test-d.ts b/tests/foundry/client/apps/forms/macro-config.test-d.ts new file mode 100644 index 000000000..8de6b9c6a --- /dev/null +++ b/tests/foundry/client/apps/forms/macro-config.test-d.ts @@ -0,0 +1,13 @@ +import { expectTypeOf } from "vitest"; + +declare const baseMacro: foundry.documents.BaseMacro; +declare const macro: Macro; + +// @ts-expect-error - a BaseMacro is not a Macro +new MacroConfig(baseMacro); + +const config = new MacroConfig(macro); +expectTypeOf(config.object).toEqualTypeOf(); + +const withCustomOptions = new MacroConfig & { custom: true }>(macro); +expectTypeOf(withCustomOptions.options).toEqualTypeOf & { custom: true }>(); diff --git a/tests/foundry/client/apps/forms/user-config.test-d.ts b/tests/foundry/client/apps/forms/user-config.test-d.ts new file mode 100644 index 000000000..8856f2704 --- /dev/null +++ b/tests/foundry/client/apps/forms/user-config.test-d.ts @@ -0,0 +1,10 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - a BaseUser is not a User +new UserConfig(new foundry.documents.BaseUser()); + +const config = new UserConfig(new User()); +expectTypeOf(config.object).toEqualTypeOf(); + +const withCustomOptions = new UserConfig & { custom: true }>(new User()); +expectTypeOf(withCustomOptions.options).toEqualTypeOf & { custom: true }>(); diff --git a/tests/foundry/client/apps/hud/chatbubble.test-d.ts b/tests/foundry/client/apps/hud/chatbubble.test-d.ts new file mode 100644 index 000000000..6218bd200 --- /dev/null +++ b/tests/foundry/client/apps/hud/chatbubble.test-d.ts @@ -0,0 +1,10 @@ +import { expectTypeOf } from "vitest"; + +declare const token: Token; + +const bubbles = new ChatBubbles(); +expectTypeOf(bubbles.template).toEqualTypeOf(); +expectTypeOf(bubbles.bubbles).toEqualTypeOf(); +expectTypeOf(bubbles.container).toEqualTypeOf(); +expectTypeOf(bubbles.say(token, "Hello World!")).toEqualTypeOf>(); +expectTypeOf(bubbles.say(token, "Hello World!", { emote: true })).toEqualTypeOf>(); diff --git a/tests/foundry/client/apps/hud/container.test-d.ts b/tests/foundry/client/apps/hud/container.test-d.ts new file mode 100644 index 000000000..3847d2324 --- /dev/null +++ b/tests/foundry/client/apps/hud/container.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +const display = new HeadsUpDisplay(); +expectTypeOf(display.token).toEqualTypeOf(); +expectTypeOf(display.tile).toEqualTypeOf(); +expectTypeOf(display.drawing).toEqualTypeOf(); +expectTypeOf(display.bubbles).toEqualTypeOf(); +expectTypeOf(display.getData()).toEqualTypeOf>(); +expectTypeOf(display.align()).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/hud/controls.test-d.ts b/tests/foundry/client/apps/hud/controls.test-d.ts new file mode 100644 index 000000000..fab7ef33e --- /dev/null +++ b/tests/foundry/client/apps/hud/controls.test-d.ts @@ -0,0 +1,59 @@ +import { assertType, expectTypeOf } from "vitest"; + +expectTypeOf(new SceneControls()).toEqualTypeOf(); +expectTypeOf(new SceneControls({ width: null })).toEqualTypeOf(); +expectTypeOf(SceneControls.defaultOptions.width).toEqualTypeOf(); + +const controls = new SceneControls(); +expectTypeOf(controls.initialize()).toEqualTypeOf(); +expectTypeOf(controls.initialize({ control: "token" })).toEqualTypeOf(); +expectTypeOf(controls.initialize({ layer: "tokens" })).toEqualTypeOf(); +expectTypeOf(controls.initialize({ tool: "select" })).toEqualTypeOf(); + +expectTypeOf(controls.controls).toEqualTypeOf(); +expectTypeOf(controls.controls.map((each) => each.tools)).toEqualTypeOf(); + +assertType({ + name: "foo", + title: "bar", + icon: "baz", + onClick: () => undefined, +}); +assertType({ + name: "foo", + title: "bar", + icon: "baz", + toggle: false, + onClick: () => undefined, +}); +assertType({ + name: "foo", + title: "bar", + icon: "baz", + button: true, + onClick: () => undefined, +}); +assertType({ + name: "foo", + title: "bar", + icon: "baz", + toggle: true, + onClick: (toggle: boolean) => toggle, +}); + +// @ts-expect-error the onClick function isn't toggleable. +assertType({ + name: "foo", + title: "bar", + icon: "baz", + toggle: false, + onClick: (toggle: boolean) => toggle, +}); + +// @ts-expect-error the onClick function isn't toggleable. +assertType({ + name: "foo", + title: "bar", + icon: "baz", + onClick: (toggle: boolean) => toggle, +}); diff --git a/tests/foundry/client/apps/hud/hotbar.test-d.ts b/tests/foundry/client/apps/hud/hotbar.test-d.ts new file mode 100644 index 000000000..b70201e81 --- /dev/null +++ b/tests/foundry/client/apps/hud/hotbar.test-d.ts @@ -0,0 +1,14 @@ +import { expectTypeOf } from "vitest"; + +const hotbar = new Hotbar(); +expectTypeOf(hotbar.page).toEqualTypeOf(); +expectTypeOf(hotbar.macros).toEqualTypeOf(); +expectTypeOf(hotbar.getData()).toEqualTypeOf>(); + +expectTypeOf(hotbar.collapse()).toEqualTypeOf>(); +expectTypeOf(hotbar.expand()).toEqualTypeOf>(); +expectTypeOf(hotbar.changePage()).toEqualTypeOf(); +expectTypeOf(hotbar.changePage(5)).toEqualTypeOf(); +expectTypeOf(hotbar.cyclePage()).toEqualTypeOf(); +expectTypeOf(hotbar.cyclePage(1)).toEqualTypeOf(); +expectTypeOf(hotbar.cyclePage(-1)).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/hud/hud.test-d.ts b/tests/foundry/client/apps/hud/hud.test-d.ts new file mode 100644 index 000000000..c4c92aef8 --- /dev/null +++ b/tests/foundry/client/apps/hud/hud.test-d.ts @@ -0,0 +1,14 @@ +import { expectTypeOf } from "vitest"; + +class MyPlaceableHud extends BasePlaceableHUD {} + +declare const token: Token; + +const hud = new MyPlaceableHud(); +expectTypeOf(hud.object).toEqualTypeOf(); + +expectTypeOf(hud.layer).toEqualTypeOf | undefined>(); +expectTypeOf(hud.bind(token)).toEqualTypeOf(); +expectTypeOf(hud.clear()).toEqualTypeOf(); + +expectTypeOf(hud.getData()).toEqualTypeOf>(); diff --git a/tests/foundry/client/apps/hud/menu.test-d.ts b/tests/foundry/client/apps/hud/menu.test-d.ts new file mode 100644 index 000000000..4dec715ef --- /dev/null +++ b/tests/foundry/client/apps/hud/menu.test-d.ts @@ -0,0 +1,13 @@ +import { expectTypeOf } from "vitest"; + +const menu = new MainMenu(); + +expectTypeOf(menu.toggle()).toEqualTypeOf(); + +const item = menu.items.reload; +if (item) { + expectTypeOf(item.label).toEqualTypeOf(); + expectTypeOf(item.icon).toEqualTypeOf(); + expectTypeOf(item.enabled).toEqualTypeOf(); + expectTypeOf(item.onClick).toEqualTypeOf<() => void>(); +} diff --git a/tests/foundry/client/apps/i18n.test-d.ts b/tests/foundry/client/apps/i18n.test-d.ts new file mode 100644 index 000000000..c1f238cbc --- /dev/null +++ b/tests/foundry/client/apps/i18n.test-d.ts @@ -0,0 +1,18 @@ +import { expectTypeOf } from "vitest"; + +type Translations = { + [K: string]: string | Translations; +}; + +new Localization(); +const localization = new Localization("en.core"); +expectTypeOf(localization.lang).toEqualTypeOf(); +expectTypeOf(localization.defaultModule).toEqualTypeOf(); +expectTypeOf(localization.translations).toEqualTypeOf(); +expectTypeOf(localization.initialize()).toEqualTypeOf>(); +expectTypeOf(localization.setLanguage("de")).toEqualTypeOf>(); +expectTypeOf(localization.has("WORLD.DetailTab")).toEqualTypeOf(); +expectTypeOf(localization.has("WORLD.DetailTab", true)).toEqualTypeOf(); +expectTypeOf(localization.localize("WORLD.DetailTab")).toEqualTypeOf(); +expectTypeOf(localization.format("DICE.ErrorNonNumeric")).toEqualTypeOf(); +expectTypeOf(localization.format("DICE.ErrorNonNumeric", { formula: "2d10" })).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/placeables/drawing-hud.test-d.ts b/tests/foundry/client/apps/placeables/drawing-hud.test-d.ts new file mode 100644 index 000000000..0824ecbff --- /dev/null +++ b/tests/foundry/client/apps/placeables/drawing-hud.test-d.ts @@ -0,0 +1,10 @@ +import { expectTypeOf } from "vitest"; + +declare const drawing: Drawing; + +const hud = new DrawingHUD(); +expectTypeOf(hud.layer).toEqualTypeOf | undefined>(); +expectTypeOf(hud.object).toEqualTypeOf(); +hud.bind(drawing); +expectTypeOf(hud.getData()).toEqualTypeOf>(); +expectTypeOf(hud.setPosition()).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/placeables/sound-config.test-d.ts b/tests/foundry/client/apps/placeables/sound-config.test-d.ts new file mode 100644 index 000000000..58e928b11 --- /dev/null +++ b/tests/foundry/client/apps/placeables/sound-config.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +declare const doc: AmbientSoundDocument; + +expectTypeOf(AmbientSoundConfig.defaultOptions).toEqualTypeOf>(); + +const config = new AmbientSoundConfig(doc); +expectTypeOf(config.title).toEqualTypeOf(); +expectTypeOf(config.close()).toEqualTypeOf>(); diff --git a/tests/foundry/client/apps/placeables/tile-config.test-d.ts b/tests/foundry/client/apps/placeables/tile-config.test-d.ts new file mode 100644 index 000000000..2c3ab72f1 --- /dev/null +++ b/tests/foundry/client/apps/placeables/tile-config.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +declare const tile: TileDocument; + +const tileConfig = new TileConfig(tile, { preview: true }); +expectTypeOf(tileConfig.document).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/placeables/tile-hud.test-d.ts b/tests/foundry/client/apps/placeables/tile-hud.test-d.ts new file mode 100644 index 000000000..ec8a98617 --- /dev/null +++ b/tests/foundry/client/apps/placeables/tile-hud.test-d.ts @@ -0,0 +1,10 @@ +import { expectTypeOf } from "vitest"; + +declare const tile: Tile; + +const hud = new TileHUD(); +expectTypeOf(hud.layer).toEqualTypeOf(); +expectTypeOf(hud.object).toEqualTypeOf(); +hud.bind(tile); +expectTypeOf(hud.getData()).toEqualTypeOf>(); +expectTypeOf(hud.setPosition()).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/placeables/token-hud.test-d.ts b/tests/foundry/client/apps/placeables/token-hud.test-d.ts new file mode 100644 index 000000000..bd901a1ee --- /dev/null +++ b/tests/foundry/client/apps/placeables/token-hud.test-d.ts @@ -0,0 +1,11 @@ +import { expectTypeOf } from "vitest"; + +declare const token: Token; + +const hud = new TokenHUD(); +expectTypeOf(hud.layer).toEqualTypeOf | undefined>(); +expectTypeOf(hud.object).toEqualTypeOf(); +hud.bind(token); + +expectTypeOf(hud.getData()).toEqualTypeOf>(); +expectTypeOf(hud.setPosition()).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts b/tests/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts new file mode 100644 index 000000000..67d00dde8 --- /dev/null +++ b/tests/foundry/client/apps/sidebar/apps/chat-popout.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +declare const message: ChatMessage; + +const popout = new ChatPopout(message); +expectTypeOf(popout.message).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts b/tests/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts new file mode 100644 index 000000000..35d15890e --- /dev/null +++ b/tests/foundry/client/apps/sidebar/tabs/combat-tracker.test-d.ts @@ -0,0 +1,18 @@ +import { expectTypeOf } from "vitest"; + +declare const combat: Combat; + +expectTypeOf(CombatTracker.defaultOptions).toEqualTypeOf(); + +const tracker = new CombatTracker(); +expectTypeOf(tracker.combats).toEqualTypeOf[]>(); +expectTypeOf(tracker.createPopout()).toEqualTypeOf(); + +expectTypeOf(tracker.initialize()).toEqualTypeOf(); +tracker.initialize({ combat: null }); +tracker.initialize({ combat: combat }); +tracker.initialize({ render: true }); +tracker.initialize({ render: false }); + +expectTypeOf(tracker.scrollToTurn()).toEqualTypeOf(); +expectTypeOf(await tracker.getData()).toEqualTypeOf(); diff --git a/tests/foundry/client/apps/sidebar/tabs/settings.test-d.ts b/tests/foundry/client/apps/sidebar/tabs/settings.test-d.ts new file mode 100644 index 000000000..f84d0e4a6 --- /dev/null +++ b/tests/foundry/client/apps/sidebar/tabs/settings.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; + +const frameViewer = new FrameViewer("https://foundryvtt.wiki/", { + title: "My Title", +}); + +expectTypeOf(frameViewer.url).toEqualTypeOf(); diff --git a/tests/foundry/client/audio/audio.test-d.ts b/tests/foundry/client/audio/audio.test-d.ts new file mode 100644 index 000000000..f13ff5a45 --- /dev/null +++ b/tests/foundry/client/audio/audio.test-d.ts @@ -0,0 +1,65 @@ +import { expectTypeOf } from "vitest"; + +const audioHelper = new AudioHelper(); +expectTypeOf(audioHelper).toEqualTypeOf(); +expectTypeOf(audioHelper.context).toEqualTypeOf(); +expectTypeOf(audioHelper.buffers).toEqualTypeOf< + Map +>(); +expectTypeOf(audioHelper.sounds).toEqualTypeOf>(); +expectTypeOf(audioHelper.playing).toEqualTypeOf>(); +expectTypeOf(audioHelper.pending).toEqualTypeOf<(() => void)[]>(); +expectTypeOf(audioHelper.locked).toEqualTypeOf(); +expectTypeOf(AudioHelper.levelAnalyserNativeInterval).toEqualTypeOf(); +expectTypeOf(AudioHelper.registerSettings()).toEqualTypeOf(); +expectTypeOf(audioHelper.create({ src: "a/path/to/some/sound/file.ogg" })).toEqualTypeOf(); +expectTypeOf( + audioHelper.create({ + src: "a/path/to/some/sound/file.ogg", + singleton: false, + preload: true, + autoplay: true, + autoplayOptions: { loop: true, offset: 42, volume: 0.5, fade: 3 }, + }), +).toEqualTypeOf(); +expectTypeOf(AudioHelper.hasAudioExtension("a/path/to/some/sound/file.ogg")).toEqualTypeOf(); +expectTypeOf(AudioHelper.getDefaultSoundName("a/path/to/some/sound/file.ogg")).toEqualTypeOf(); +expectTypeOf(audioHelper.play("a/path/to/some/sound/file.ogg")).toEqualTypeOf>(); +expectTypeOf( + audioHelper.play("a/path/to/some/sound/file.ogg", { loop: true, offset: 42, volume: 0.5, fade: 3 }), +).toEqualTypeOf>(); +expectTypeOf(audioHelper.awaitFirstGesture()).toEqualTypeOf>(); +expectTypeOf(audioHelper.preload("a/path/to/some/sound/file.ogg")).toEqualTypeOf>(); + +declare const socket: io.Socket; + +expectTypeOf(AudioHelper._activateSocketListeners(socket)).toEqualTypeOf(); +expectTypeOf( + AudioHelper.play({ + src: "a/path/to/some/sound/file.ogg", + }), +).toEqualTypeOf>(); +expectTypeOf( + AudioHelper.play( + { + src: "a/path/to/some/sound/file.ogg", + volume: 0.8, + autoplay: false, + loop: true, + }, + true, + ), +).toEqualTypeOf>(); +expectTypeOf(AudioHelper.preloadSound("a/path/to/some/sound/file.ogg")).toEqualTypeOf>(); +expectTypeOf(AudioHelper.inputToVolume(0.5)).toEqualTypeOf(); +expectTypeOf(AudioHelper.inputToVolume("0.5", 1.7)).toEqualTypeOf(); +expectTypeOf(AudioHelper.volumeToInput(0.5)).toEqualTypeOf(); +expectTypeOf(AudioHelper.volumeToInput(0.5, 1.7)).toEqualTypeOf(); +expectTypeOf(audioHelper.getAudioContext()).toEqualTypeOf(); + +declare const stream: MediaStream; +declare const callback: (maxDecibel: number, fftArray: Float32Array) => void; + +expectTypeOf(audioHelper.startLevelReports("some id", stream, callback)).toEqualTypeOf(); +expectTypeOf(audioHelper.startLevelReports("some id", stream, callback, 60, 0.2)).toEqualTypeOf(); +expectTypeOf(audioHelper.stopLevelReports("some id")).toEqualTypeOf(); diff --git a/tests/foundry/client/audio/container.test-d.ts b/tests/foundry/client/audio/container.test-d.ts new file mode 100644 index 000000000..d1e1ac6ca --- /dev/null +++ b/tests/foundry/client/audio/container.test-d.ts @@ -0,0 +1,22 @@ +import { expectTypeOf } from "vitest"; + +const audioContainer = new AudioContainer("a/path/to/some/sound/file.ogg"); +expectTypeOf(audioContainer).toEqualTypeOf(); +expectTypeOf(audioContainer.src).toEqualTypeOf(); +expectTypeOf(audioContainer.sourceNode).toEqualTypeOf< + AudioBufferSourceNode | MediaElementAudioSourceNode | undefined +>(); +expectTypeOf(audioContainer.gainNode).toEqualTypeOf(); +expectTypeOf(audioContainer.isBuffer).toEqualTypeOf(); +expectTypeOf(audioContainer.loaded).toEqualTypeOf(); +expectTypeOf(audioContainer.failed).toEqualTypeOf(); +expectTypeOf(audioContainer.playing).toEqualTypeOf(); +expectTypeOf(audioContainer.loop).toEqualTypeOf(); +expectTypeOf(AudioContainer.MAX_BUFFER_DURATION).toEqualTypeOf(); +expectTypeOf(audioContainer.buffer).toEqualTypeOf(); +expectTypeOf(audioContainer.context).toEqualTypeOf(); +expectTypeOf(audioContainer.duration).toEqualTypeOf(); +expectTypeOf(audioContainer.element).toEqualTypeOf(); +expectTypeOf(audioContainer.load()).toEqualTypeOf>(); +expectTypeOf(audioContainer.play(0, () => undefined)).toEqualTypeOf(); +expectTypeOf(audioContainer.stop()).toEqualTypeOf(); diff --git a/tests/foundry/client/audio/sound.test-d.ts b/tests/foundry/client/audio/sound.test-d.ts new file mode 100644 index 000000000..4c5a76a19 --- /dev/null +++ b/tests/foundry/client/audio/sound.test-d.ts @@ -0,0 +1,40 @@ +import { expectTypeOf } from "vitest"; + +const sound = new Sound("a/path/to/some/sound/file.ogg"); + +expectTypeOf(sound).toEqualTypeOf(); +expectTypeOf(sound.id).toEqualTypeOf(); +expectTypeOf(sound.src).toEqualTypeOf(); +expectTypeOf(sound.container).toEqualTypeOf(); +expectTypeOf(sound.startTime).toEqualTypeOf(); +expectTypeOf(sound.pausedTime).toEqualTypeOf(); +expectTypeOf(sound.events).toEqualTypeOf(); +expectTypeOf(sound.loading).toEqualTypeOf | undefined>(); +expectTypeOf(sound.context).toEqualTypeOf(); +expectTypeOf(sound.node).toEqualTypeOf(); +expectTypeOf(sound.gain).toEqualTypeOf(); +expectTypeOf(sound.currentTime).toEqualTypeOf(); +expectTypeOf(sound.duration).toEqualTypeOf(); +expectTypeOf(sound.loaded).toEqualTypeOf(); +expectTypeOf(sound.failed).toEqualTypeOf(); +expectTypeOf(sound.playing).toEqualTypeOf(); +expectTypeOf(sound.loop).toEqualTypeOf(); +expectTypeOf(sound.volume).toEqualTypeOf(); +expectTypeOf(sound.fade(0)).toEqualTypeOf>(); +expectTypeOf(sound.fade(0, { duration: 42, from: 0.5, type: "exponential" })).toEqualTypeOf>(); +expectTypeOf(sound.load()).toEqualTypeOf>(); +expectTypeOf( + sound.load({ autoplay: true, autoplayOptions: { loop: true, offset: 2, volume: 0.7, fade: 3 } }), +).toEqualTypeOf>(); +expectTypeOf(sound.play()).toEqualTypeOf(); +expectTypeOf(sound.play({ loop: true, offset: 2, volume: 0.7, fade: 3 })).toEqualTypeOf(); +expectTypeOf(sound.pause()).toEqualTypeOf(); +expectTypeOf(sound.stop()).toEqualTypeOf(); + +declare const soundCallback: (sound: Sound) => void; + +expectTypeOf(sound.schedule(soundCallback, 42)).toEqualTypeOf>(); +expectTypeOf(sound.emit("pause")).toEqualTypeOf(); +expectTypeOf(sound.off("end", 42)).toEqualTypeOf(); +expectTypeOf(sound.off("start", soundCallback)).toEqualTypeOf(); +expectTypeOf(sound.on("stop", soundCallback)).toEqualTypeOf(); diff --git a/test-d/foundry/client/av/master.test-d.ts b/tests/foundry/client/av/master.test-d.ts similarity index 79% rename from test-d/foundry/client/av/master.test-d.ts rename to tests/foundry/client/av/master.test-d.ts index 65d169da3..66a55ee9a 100644 --- a/test-d/foundry/client/av/master.test-d.ts +++ b/tests/foundry/client/av/master.test-d.ts @@ -1,4 +1,4 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; declare class CustomAVCLient extends AVClient { updateLocalStream(): Promise; @@ -27,7 +27,7 @@ CONFIG.WebRTC.clientClass = CustomAVCLient; const avMaster = new AVMaster(); -expectType(avMaster.client.customProperty); +expectTypeOf(avMaster.client.customProperty).toEqualTypeOf(); if (game instanceof Game) { - expectType(game?.webrtc?.client.customProperty); + expectTypeOf(game?.webrtc?.client.customProperty).toEqualTypeOf(); } diff --git a/test-d/foundry/client/av/settings.test-d.ts b/tests/foundry/client/av/settings.test-d.ts similarity index 64% rename from test-d/foundry/client/av/settings.test-d.ts rename to tests/foundry/client/av/settings.test-d.ts index 2552d0f7f..774688b84 100644 --- a/test-d/foundry/client/av/settings.test-d.ts +++ b/tests/foundry/client/av/settings.test-d.ts @@ -1,4 +1,4 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; interface CustomVoiceModes { SOME_CUSTOM_MODE: "custom"; @@ -17,7 +17,7 @@ AVSettings.VOICE_MODES = { SOME_CUSTOM_MODE: "custom", }; -expectType(AVSettings.VOICE_MODES); +expectTypeOf(AVSettings.VOICE_MODES).toEqualTypeOf(); const avMaster = new AVMaster(); -expectType<"custom">(avMaster.settings.client.voice.mode); +expectTypeOf(avMaster.settings.client.voice.mode).toEqualTypeOf<"custom">(); diff --git a/tests/foundry/client/core/hooks.test-d.ts b/tests/foundry/client/core/hooks.test-d.ts new file mode 100644 index 000000000..690d08911 --- /dev/null +++ b/tests/foundry/client/core/hooks.test-d.ts @@ -0,0 +1,25 @@ +import { expectTypeOf } from "vitest"; +import "../../../../index"; + +Hooks.on("canvasInit", (canvas) => { + expectTypeOf(canvas).toEqualTypeOf(); +}); +Hooks.on("fooBar", (baz, bar) => { + expectTypeOf(baz).toEqualTypeOf(); + expectTypeOf(bar).toEqualTypeOf(); + return true; +}); +Hooks.on>("closeFormApplication", (app, jq) => { + expectTypeOf(app).toEqualTypeOf(); + expectTypeOf(jq).toEqualTypeOf(); +}); + +Hooks.on("error", (...args) => { + if (args[0] === "Canvas#draw") expectTypeOf(args[2].layer).toEqualTypeOf(); +}); +Hooks.on("error", (...args) => { + if (args[0] === "Game#initializeCanvas") expectTypeOf(args[2].foo).toEqualTypeOf(); +}); +Hooks.on("error", (...args) => { + if (args[0] === "MyClass#myMethod") expectTypeOf(args[2].foo).toEqualTypeOf(); +}); diff --git a/tests/foundry/client/core/settings.test-d.ts b/tests/foundry/client/core/settings.test-d.ts new file mode 100644 index 000000000..50b71e19e --- /dev/null +++ b/tests/foundry/client/core/settings.test-d.ts @@ -0,0 +1,79 @@ +import { expectTypeOf } from "vitest"; +import "../../index"; + +const clientSettings = new ClientSettings([]); + +declare global { + // eslint-disable-next-line + namespace ClientSettings { + interface Values { + "foo.bar": boolean; + "some.numberSetting": number; + "some.stringSetting": string; + } + } +} + +clientSettings.register("foo", "bar", { + scope: "world", + // @ts-expect-error - The setting foo.bar was declared as a boolean not a string + type: String, +}); + +// @ts-expect-error - The setting foo.bar was declared as a boolean not a string +clientSettings.set("foo", "bar", "true"); + +clientSettings.register("foo", "bar", { + scope: "world", + type: Boolean, + config: true, + default: true, +}); +clientSettings.set("foo", "bar", false); +expectTypeOf(clientSettings.get("foo", "bar")).toEqualTypeOf(); + +expectTypeOf(clientSettings.get("foo", "baz")).toEqualTypeOf(); + +clientSettings.register("some", "stringSetting", { + scope: "world", + type: String, + // @ts-expect-error - Range shouldn't be valid for string settings + range: { + min: 0, + max: 42, + step: 1, + }, +}); + +clientSettings.register("some", "numberSetting", { + scope: "world", + type: Number, + range: { + min: 0, + max: 42, + step: 1, + }, +}); + +clientSettings.register("some", "numberSetting", { + scope: "world", + type: Number, + // @ts-expect-error - Can only use filePicker for string settings + filePicker: "audio", +}); + +clientSettings.register("some", "stringSetting", { + scope: "world", + type: String, + filePicker: "audio", +}); + +// core settings + +expectTypeOf(clientSettings.get("core", "combatTrackerConfig")).toEqualTypeOf< + { resource: string; skipDefeated: boolean } | {} +>(); +expectTypeOf(clientSettings.get("core", "compendiumConfiguration")).toEqualTypeOf< + Partial> +>(); +expectTypeOf(clientSettings.get("core", "rollMode")).toEqualTypeOf(); diff --git a/tests/foundry/client/core/time.test-d.ts b/tests/foundry/client/core/time.test-d.ts new file mode 100644 index 000000000..efd7cf92a --- /dev/null +++ b/tests/foundry/client/core/time.test-d.ts @@ -0,0 +1,17 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(GameTime.SYNC_INTERVAL_MS).toEqualTypeOf(); +new GameTime(undefined); +new GameTime(null); + +if (game instanceof Game) { + const time = new GameTime(game.socket); + expectTypeOf(time.serverTime).toEqualTypeOf(); + expectTypeOf(time.worldTime).toEqualTypeOf(); + expectTypeOf(time.advance(100)).toEqualTypeOf>(); + expectTypeOf(time.sync(game.socket)).toEqualTypeOf>(); + expectTypeOf(time.sync(undefined)).toEqualTypeOf>(); + expectTypeOf(time.sync(null)).toEqualTypeOf>(); + expectTypeOf(time.onUpdateWorldTime(100)).toEqualTypeOf(); + expectTypeOf(game.settings.get("core", "time")).toEqualTypeOf(); +} diff --git a/tests/foundry/client/core/utils.test-d.ts b/tests/foundry/client/core/utils.test-d.ts new file mode 100644 index 000000000..db010174e --- /dev/null +++ b/tests/foundry/client/core/utils.test-d.ts @@ -0,0 +1,5 @@ +import { assertType } from "vitest"; + +// prove that they are global +assertType(saveDataToFile); +assertType(readTextFromFile); diff --git a/tests/foundry/client/data/abstract/canvas-document.test-d.ts b/tests/foundry/client/data/abstract/canvas-document.test-d.ts new file mode 100644 index 000000000..c2d0b3ff1 --- /dev/null +++ b/tests/foundry/client/data/abstract/canvas-document.test-d.ts @@ -0,0 +1,24 @@ +import type * as data from "../../../../../src/foundry/common/data/data.mjs/index.js"; + +import { assertType, expectTypeOf } from "vitest"; + +const doc = new AmbientLightDocument(); + +// Test the inheritance +expectTypeOf(doc.documentName).toEqualTypeOf<"AmbientLight">(); // Document +expectTypeOf(doc.uuid).toEqualTypeOf(); // clientDocumentMixin +// TODO: change to > | null> once the circular reference problem has been solved +expectTypeOf(doc.object).toEqualTypeOf(); // canvasDocumentMixin +expectTypeOf(doc.isGlobal).toEqualTypeOf(); // class itself + +// Test the inheritance of static members +expectTypeOf(AmbientLightDocument.documentName).toEqualTypeOf(); // Document +expectTypeOf(AmbientLightDocument.schema).toEqualTypeOf(); // Base-Document +expectTypeOf(AmbientLightDocument.createDialog()).toEqualTypeOf>(); // ClientDocumentMixin + +// Test the props +// TODO: change to > | null> once the circular reference problem has been solved +assertType(doc.object); +// TODO: change to > | null> once the circular reference problem has been solved +assertType(doc.layer); +expectTypeOf(doc.rendered).toEqualTypeOf(); diff --git a/tests/foundry/client/data/abstract/client-document.test-d.ts b/tests/foundry/client/data/abstract/client-document.test-d.ts new file mode 100644 index 000000000..afbd24b27 --- /dev/null +++ b/tests/foundry/client/data/abstract/client-document.test-d.ts @@ -0,0 +1,23 @@ +import type * as data from "../../../../../src/foundry/common/data/data.mjs/index.js"; + +import { expectTypeOf } from "vitest"; + +const doc = new Item(); + +// Test the inheritance +expectTypeOf(doc.documentName).toEqualTypeOf<"Item">(); // Document +expectTypeOf(doc.migrateSystemData()).toEqualTypeOf(); // Base-Document +expectTypeOf(doc.uuid).toEqualTypeOf(); // ClientDocumentMixin +expectTypeOf(doc.transferredEffects).toEqualTypeOf(); // class itself + +// Test the inheritance of static members +expectTypeOf(Item.documentName).toEqualTypeOf(); // Document +expectTypeOf(Item.schema).toEqualTypeOf(); // Base-Document +expectTypeOf(Item.createDialog()).toEqualTypeOf>(); // ClientDocumentMixin + +// Properties +// TODO: change to > | null> once the circular reference problem has been solved +expectTypeOf(doc.sheet).toEqualTypeOf(); + +// ensure source can be used to create a new document with createDialog +expectTypeOf(Item.createDialog(doc.toObject())).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/collections/actors.test-d.ts b/tests/foundry/client/data/collections/actors.test-d.ts new file mode 100644 index 000000000..05951a036 --- /dev/null +++ b/tests/foundry/client/data/collections/actors.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; + +const actors = new Actors(); +expectTypeOf(actors.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(actors.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(actors.directory).toEqualTypeOf(); +expectTypeOf(actors.tokens["foo"]).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/combats.test-d.ts b/tests/foundry/client/data/collections/combats.test-d.ts new file mode 100644 index 000000000..26fbfe4b6 --- /dev/null +++ b/tests/foundry/client/data/collections/combats.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const combatEncounters = new CombatEncounters(); +expectTypeOf(combatEncounters.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(combatEncounters.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(combatEncounters.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/compendium.test-d.ts b/tests/foundry/client/data/collections/compendium.test-d.ts new file mode 100644 index 000000000..ce58647b3 --- /dev/null +++ b/tests/foundry/client/data/collections/compendium.test-d.ts @@ -0,0 +1,45 @@ +import { expectTypeOf } from "vitest"; + +const metadata = { + type: "JournalEntry" as const, + label: "Important Plotholes", + name: "plotholes", + package: "some-package", + path: "path/to/file", + private: false, +}; + +const compendiumCollection = new CompendiumCollection(metadata); +expectTypeOf(compendiumCollection.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(compendiumCollection.toJSON()).toEqualTypeOf< + Array["data"]["_source"]> +>(); + +expectTypeOf((await compendiumCollection.getIndex()).get("some id", { strict: true })).toEqualTypeOf< + { _id: string } & Partial +>(); + +const itemCollection = new CompendiumCollection({ + type: "Item", + label: "Important items", + name: "items", + package: "other-package", + path: "path/to/items", + private: false, +}); +expectTypeOf((await itemCollection.getIndex()).get("some id", { strict: true })).toEqualTypeOf< + { _id: string } & Partial +>(); +expectTypeOf( + (await itemCollection.getIndex({ fields: ["name", "effects", "data"] })).get("some id", { strict: true }), +).toEqualTypeOf<{ _id: string } & Partial>(); + +// @ts-expect-error - "nonExistentField" is not one of the fields declared above +await itemCollection.getIndex({ fields: ["nonExistentField"] }); + +expectTypeOf(await itemCollection.getDocuments()).toEqualTypeOf[]>(); // get all items +expectTypeOf(await itemCollection.getDocuments({})).toEqualTypeOf[]>(); // get all items +expectTypeOf(await itemCollection.getDocuments({ name: "foo" })).toEqualTypeOf[]>(); // get all items called "foo" +expectTypeOf( + await itemCollection.getDocuments({ $or: [{ name: "baz" }, { name: "bar" }], effects: { $size: 2 } }), // only get items called "baz" or "bar" that have exactly 2 effects +).toEqualTypeOf[]>(); diff --git a/tests/foundry/client/data/collections/fog.test-d.ts b/tests/foundry/client/data/collections/fog.test-d.ts new file mode 100644 index 000000000..7a3be5e73 --- /dev/null +++ b/tests/foundry/client/data/collections/fog.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const fogExplorations = new FogExplorations(); +expectTypeOf(fogExplorations.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(fogExplorations.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(fogExplorations.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/folder.test-d.ts b/tests/foundry/client/data/collections/folder.test-d.ts new file mode 100644 index 000000000..7ec3c2d5a --- /dev/null +++ b/tests/foundry/client/data/collections/folder.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const folders = new Folders(); +expectTypeOf(folders.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(folders.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(folders.directory).toEqualTypeOf | undefined>(); diff --git a/tests/foundry/client/data/collections/items.test-d.ts b/tests/foundry/client/data/collections/items.test-d.ts new file mode 100644 index 000000000..1dadd4885 --- /dev/null +++ b/tests/foundry/client/data/collections/items.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const items = new Items(); +expectTypeOf(items.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(items.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(items.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/journal.test-d.ts b/tests/foundry/client/data/collections/journal.test-d.ts new file mode 100644 index 000000000..8c355d419 --- /dev/null +++ b/tests/foundry/client/data/collections/journal.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const journal = new Journal(); +expectTypeOf(journal.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(journal.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(journal.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/macros.test-d.ts b/tests/foundry/client/data/collections/macros.test-d.ts new file mode 100644 index 000000000..6d4af5b40 --- /dev/null +++ b/tests/foundry/client/data/collections/macros.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const macros = new Macros(); +expectTypeOf(macros.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(macros.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(macros.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/messages.test-d.ts b/tests/foundry/client/data/collections/messages.test-d.ts new file mode 100644 index 000000000..4dcbe57fb --- /dev/null +++ b/tests/foundry/client/data/collections/messages.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const messages = new Messages(); +expectTypeOf(messages.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(messages.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(messages.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/playlists.test-d.ts b/tests/foundry/client/data/collections/playlists.test-d.ts new file mode 100644 index 000000000..c5b7121c0 --- /dev/null +++ b/tests/foundry/client/data/collections/playlists.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; +import type { PlaylistDataSource } from "../../../../../src/foundry/common/data/data.mjs/playlistData"; + +const playlists = new Playlists(); +expectTypeOf(playlists.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(playlists.toJSON()).toEqualTypeOf<(PlaylistDataSource & { _id: string })[]>(); +expectTypeOf(playlists.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/scenes.test-d.ts b/tests/foundry/client/data/collections/scenes.test-d.ts new file mode 100644 index 000000000..1be092baf --- /dev/null +++ b/tests/foundry/client/data/collections/scenes.test-d.ts @@ -0,0 +1,8 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(Scenes.documentName).toEqualTypeOf<"Scene">(); + +const scenes = new Scenes(); +expectTypeOf(scenes.active).toEqualTypeOf | undefined>(); +expectTypeOf(scenes.current).toEqualTypeOf | undefined>(); +expectTypeOf(scenes.viewed).toEqualTypeOf | undefined>(); diff --git a/tests/foundry/client/data/collections/settings.test-d.ts b/tests/foundry/client/data/collections/settings.test-d.ts new file mode 100644 index 000000000..442265d66 --- /dev/null +++ b/tests/foundry/client/data/collections/settings.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; + +const worldSettings = new WorldSettings(); +expectTypeOf(worldSettings.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(worldSettings.getSetting("foo")).toEqualTypeOf | undefined>(); +expectTypeOf(worldSettings.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(worldSettings.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/tables.test-d.ts b/tests/foundry/client/data/collections/tables.test-d.ts new file mode 100644 index 000000000..517a9ca67 --- /dev/null +++ b/tests/foundry/client/data/collections/tables.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; +import type { RollTableDataSource } from "../../../../../src/foundry/common/data/data.mjs/rollTableData"; + +const rollTables = new RollTables(); +expectTypeOf(rollTables.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(rollTables.toJSON()).toEqualTypeOf<(RollTableDataSource & { _id: string })[]>(); +expectTypeOf(rollTables.directory).toEqualTypeOf(); diff --git a/tests/foundry/client/data/collections/users.test-d.ts b/tests/foundry/client/data/collections/users.test-d.ts new file mode 100644 index 000000000..d19315fca --- /dev/null +++ b/tests/foundry/client/data/collections/users.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const users = new Users(); +expectTypeOf(users.get("", { strict: true })).toEqualTypeOf>(); +expectTypeOf(users.toJSON()).toEqualTypeOf["data"]["_source"][]>(); +expectTypeOf(users.directory).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/documents/active-effect.test-d.ts b/tests/foundry/client/data/documents/active-effect.test-d.ts new file mode 100644 index 000000000..635fff8f4 --- /dev/null +++ b/tests/foundry/client/data/documents/active-effect.test-d.ts @@ -0,0 +1,26 @@ +import { expectTypeOf } from "vitest"; + +const eff = new ActiveEffect({}); + +declare global { + interface FlagConfig { + ActiveEffect: { + mySystem?: { + importantFlag?: boolean; + }; + }; + } +} + +expectTypeOf(eff.getFlag("mySystem", "importantFlag")).toEqualTypeOf(); +expectTypeOf(eff.getFlag("core", "statusId")).toEqualTypeOf(); +expectTypeOf(eff.getFlag("core", "overlay")).toEqualTypeOf(); + +eff.setFlag("core", "statusId", "foo"); +eff.setFlag("core", "overlay", false); + +// @ts-expect-error the setting core.statusId is a string not a number +eff.setFlag("core", "statusId", 0); + +// @ts-expect-error the setting core.overlay is a boolean not a number +eff.setFlag("core", "overlay", 0); diff --git a/tests/foundry/client/data/documents/actor.test-d.ts b/tests/foundry/client/data/documents/actor.test-d.ts new file mode 100644 index 000000000..88f48a60c --- /dev/null +++ b/tests/foundry/client/data/documents/actor.test-d.ts @@ -0,0 +1,33 @@ +import { assertType, expectTypeOf } from "vitest"; + +declare const document: boolean; + +const actor = new Actor({ name: "Beren", type: "npc" }); +expectTypeOf(actor.getActiveTokens()).toEqualTypeOf(); +expectTypeOf(actor.getActiveTokens(false, false)).toEqualTypeOf(); +expectTypeOf(actor.getActiveTokens(false, true)).toEqualTypeOf(); +expectTypeOf(actor.getActiveTokens(false, document)).toEqualTypeOf(); + +assertType(actor.itemTypes["armor"][0].data); + +interface CharacterActor { + data: foundry.data.ActorData & { type: "character"; _source: { type: "character" } }; +} +class CharacterActor extends Actor { + someCustomFunction() { + expectTypeOf(this.data.type).toEqualTypeOf<"character">(); + expectTypeOf(this.data.data.movement).toEqualTypeOf(); + expectTypeOf(this.data._source.type).toEqualTypeOf<"character">(); + expectTypeOf(this.data._source.data.health).toEqualTypeOf(); + } +} + +declare const character: CharacterActor; + +expectTypeOf(character.data.type).toEqualTypeOf<"character">(); +expectTypeOf(character.data.data.movement).toEqualTypeOf(); +expectTypeOf(character.data._source.type).toEqualTypeOf<"character">(); +expectTypeOf(character.data._source.data.health).toEqualTypeOf(); + +expectTypeOf(character.toObject().type).toEqualTypeOf<"character">(); +expectTypeOf(character.toObject().data.health).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/card.test-d.ts b/tests/foundry/client/data/documents/card.test-d.ts new file mode 100644 index 000000000..1ee2732e4 --- /dev/null +++ b/tests/foundry/client/data/documents/card.test-d.ts @@ -0,0 +1,99 @@ +import { expectTypeOf } from "vitest"; + +const card = new Card({ name: "Just a deck of cards" }); +const cards = new Cards({ name: "Some Card Deck", type: "german" }); + +expectTypeOf(card.back).toEqualTypeOf(); +expectTypeOf(card.face).toEqualTypeOf(); +expectTypeOf(card.backImg).toEqualTypeOf(); +expectTypeOf(card.img).toEqualTypeOf(); +expectTypeOf(card.name).toEqualTypeOf(); +expectTypeOf(card.source).toEqualTypeOf(); +expectTypeOf(card.isHome).toEqualTypeOf(); +expectTypeOf(card.showFace).toEqualTypeOf(); +expectTypeOf(card.hasNextFace).toEqualTypeOf(); +expectTypeOf(card.hasPreviousFace).toEqualTypeOf(); + +// flip +expectTypeOf(card.flip()).toEqualTypeOf>(); +expectTypeOf(card.flip(1)).toEqualTypeOf>(); +expectTypeOf(card.flip(null)).toEqualTypeOf>(); +expectTypeOf(card.flip(undefined)).toEqualTypeOf>(); + +// pass +expectTypeOf(card.pass(cards)).toEqualTypeOf>(); +expectTypeOf( + card.pass(cards, { + action: "some custom action", + updateData: { value: 3 }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +card.pass(cards, { unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +card.pass(cards, { updateData: { unknownProp: 0 } }); + +// play +expectTypeOf(card.play(cards)).toEqualTypeOf>(); +expectTypeOf( + card.play(cards, { + action: "some custom action", + updateData: { value: 3 }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +card.play(cards, { unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +card.play(cards, { updateData: { unknownProp: 0 } }); + +// discard +expectTypeOf(card.discard(cards)).toEqualTypeOf>(); +expectTypeOf( + card.discard(cards, { + action: "some custom action", + updateData: { value: 3 }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +card.discard(cards, { unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +card.discard(cards, { updateData: { unknownProp: 0 } }); + +// discard +expectTypeOf(card.reset()).toEqualTypeOf>(); +expectTypeOf( + card.reset({ + updateData: { value: 3 }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +card.reset({ unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +card.reset({ updateData: { unknownProp: 0 } }); + +// toMessage +expectTypeOf(card.toMessage()).toEqualTypeOf>(); +expectTypeOf( + card.toMessage( + { + speaker: { + alias: "The Speaker", + }, + }, + { + noHook: true, + }, + ), +).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/documents/cards.test-d.ts b/tests/foundry/client/data/documents/cards.test-d.ts new file mode 100644 index 000000000..2ccf95017 --- /dev/null +++ b/tests/foundry/client/data/documents/cards.test-d.ts @@ -0,0 +1,124 @@ +import { expectTypeOf } from "vitest"; + +const cards = new Cards({ name: "Just a deck of cards", type: "german" }); + +expectTypeOf(cards.thumbnail).toEqualTypeOf(); +expectTypeOf(cards.availableCards).toEqualTypeOf(); +expectTypeOf(cards.drawnCards).toEqualTypeOf(); + +// deal +expectTypeOf(cards.deal([cards])).toEqualTypeOf>(); +expectTypeOf(cards.deal([cards], 2)).toEqualTypeOf>(); +expectTypeOf( + cards.deal([cards], 2, { + how: foundry.CONST.CARD_DRAW_MODES.RANDOM, + action: "some custom action", + updateData: { value: 3 }, + chatNotification: true, + }), +).toEqualTypeOf>(); +expectTypeOf( + cards.deal([cards], undefined, { + how: foundry.CONST.CARD_DRAW_MODES.RANDOM, + action: "some custom action", + updateData: { value: 3 }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.deal([cards], undefined, { unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.deal([cards], undefined, { updateData: { unknownProp: 3 } }); + +// @ts-expect-error - There is no argument for the ids parameter +cards.pass(cards); + +expectTypeOf(cards.pass(cards, ["foo"])).toEqualTypeOf>(); +expectTypeOf( + cards.pass(cards, ["foo"], { + action: "some custom action", + updateData: { value: 3 }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.pass(cards, ["foo"], { unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.pass(cards, ["foo"], { updateData: { unknownProp: 0 } }); + +// draw +expectTypeOf(cards.draw(cards)).toEqualTypeOf>(); +expectTypeOf(cards.draw(cards, 2)).toEqualTypeOf>(); +expectTypeOf( + cards.draw(cards, 2, { + how: foundry.CONST.CARD_DRAW_MODES.RANDOM, + action: "some custom action", + updateData: { value: 3 }, + }), +).toEqualTypeOf>(); +expectTypeOf( + cards.draw(cards, undefined, { + how: foundry.CONST.CARD_DRAW_MODES.RANDOM, + action: "some custom action", + updateData: { value: 3 }, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.draw(cards, undefined, { unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.draw(cards, undefined, { updateData: { unknownProp: 3 } }); + +// shuffle +expectTypeOf(cards.shuffle()).toEqualTypeOf>(); +expectTypeOf( + cards.shuffle({ + updateData: { + value: 1, + }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.shuffle({ unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.shuffle({ updateData: { unknownProp: 3 } }); + +// reset +expectTypeOf(cards.reset()).toEqualTypeOf>(); +expectTypeOf( + cards.reset({ + updateData: { + value: 1, + }, + chatNotification: true, + }), +).toEqualTypeOf>(); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.reset({ unknownProp: 0 }); + +// @ts-expect-error - "unknownProp" is not a valid option +cards.reset({ updateData: { unknownProp: 3 } }); + +// dealDialog +expectTypeOf(cards.dealDialog()).toEqualTypeOf>(); + +// drawDialog +expectTypeOf(cards.drawDialog()).toEqualTypeOf>(); + +// passDialog +expectTypeOf(cards.passDialog()).toEqualTypeOf>(); + +// playDialog +expectTypeOf(cards.playDialog(new Card({ name: "Some Card" }))).toEqualTypeOf>(); + +// resetDialog +expectTypeOf(cards.resetDialog()).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/documents/chat-message.test-d.ts b/tests/foundry/client/data/documents/chat-message.test-d.ts new file mode 100644 index 000000000..2ceb239e0 --- /dev/null +++ b/tests/foundry/client/data/documents/chat-message.test-d.ts @@ -0,0 +1,86 @@ +import type { ChatSpeakerData } from "../../../../../src/foundry/common/data/data.mjs/chatSpeakerData"; +import type { ConstructorDataType } from "../../../../../src/types/helperTypes"; + +import { expectTypeOf } from "vitest"; + +expectTypeOf(new ChatMessage()).toEqualTypeOf(); +expectTypeOf(new ChatMessage({})).toEqualTypeOf(); + +expectTypeOf(ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.BLIND)).toEqualTypeOf< + ConstructorDataType +>(); +expectTypeOf(ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.PRIVATE)).toEqualTypeOf< + ConstructorDataType +>(); +expectTypeOf(ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.PUBLIC)).toEqualTypeOf< + ConstructorDataType +>(); +expectTypeOf(ChatMessage.applyRollMode({}, CONST.DICE_ROLL_MODES.SELF)).toEqualTypeOf< + ConstructorDataType +>(); + +expectTypeOf(ChatMessage.applyRollMode(new foundry.data.ChatMessageData(), "roll")).toEqualTypeOf< + ConstructorDataType +>(); + +declare global { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace CONFIG { + // eslint-disable-next-line @typescript-eslint/no-namespace + namespace Dice { + interface RollModes { + "custom-roll-mode": "Some Custom Roll Mode"; + } + } + } +} + +expectTypeOf(ChatMessage.applyRollMode(new foundry.data.ChatMessageData(), "custom-roll-mode")).toEqualTypeOf< + ConstructorDataType +>(); + +// @ts-expect-error - "unknown-roll-mode" is not a valid roll mode +ChatMessage.applyRollMode(new foundry.data.ChatMessageData(), "unknown-roll-mode"); + +expectTypeOf(ChatMessage.getSpeaker()).toEqualTypeOf(); +expectTypeOf(ChatMessage.getSpeaker({})).toEqualTypeOf(); +if (game instanceof Game) { + expectTypeOf(ChatMessage.getSpeaker({ scene: game.scenes?.active })).toEqualTypeOf(); + expectTypeOf(ChatMessage.getSpeaker({ actor: game.user?.character })).toEqualTypeOf(); + expectTypeOf( + ChatMessage.getSpeaker({ + scene: game.scenes?.active, + actor: game.user?.character, + token: new TokenDocument(), + alias: "Mario", + }), + ).toEqualTypeOf(); +} +expectTypeOf(ChatMessage.getSpeaker({ token: new TokenDocument() })).toEqualTypeOf(); +expectTypeOf(ChatMessage.getSpeaker({ alias: "Mario" })).toEqualTypeOf(); + +expectTypeOf(ChatMessage.getSpeakerActor(ChatMessage.getSpeaker())).toEqualTypeOf(); +expectTypeOf(ChatMessage.getWhisperRecipients("Mario")).toEqualTypeOf[]>(); + +const chat = new ChatMessage(); +expectTypeOf(chat.alias).toEqualTypeOf(); +expectTypeOf(chat.isAuthor).toEqualTypeOf(); +expectTypeOf(chat.isContentVisible).toEqualTypeOf(); +expectTypeOf(chat.isRoll).toEqualTypeOf(); +expectTypeOf(chat.roll).toEqualTypeOf(); +expectTypeOf(chat.visible).toEqualTypeOf(); +expectTypeOf(chat.user).toEqualTypeOf(); +expectTypeOf(chat.prepareData()).toEqualTypeOf(); +expectTypeOf(chat.applyRollMode(CONST.DICE_ROLL_MODES.BLIND)).toEqualTypeOf(); +expectTypeOf(chat.applyRollMode(CONST.DICE_ROLL_MODES.PRIVATE)).toEqualTypeOf(); +expectTypeOf(chat.applyRollMode(CONST.DICE_ROLL_MODES.PUBLIC)).toEqualTypeOf(); +expectTypeOf(chat.applyRollMode(CONST.DICE_ROLL_MODES.SELF)).toEqualTypeOf(); +expectTypeOf(chat.applyRollMode("roll")).toEqualTypeOf(); +expectTypeOf(chat.applyRollMode("custom-roll-mode")).toEqualTypeOf(); + +// @ts-expect-error - "unknown-roll-mode" is not a valid roll mode +chat.applyRollMode("unknown-roll-mode"); + +expectTypeOf(chat.getRollData()).toEqualTypeOf(); +expectTypeOf(chat.getHTML()).toEqualTypeOf>(); +expectTypeOf(chat.export()).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/combatant.test-d.ts b/tests/foundry/client/data/documents/combatant.test-d.ts new file mode 100644 index 000000000..ec028908d --- /dev/null +++ b/tests/foundry/client/data/documents/combatant.test-d.ts @@ -0,0 +1,22 @@ +import { expectTypeOf } from "vitest"; + +const combatant = new Combatant({}, {}); + +// static properties of `BaseCombatant` +expectTypeOf(Combatant.schema).toEqualTypeOf(); + +// properties +expectTypeOf(combatant.pack).toEqualTypeOf(); +expectTypeOf(combatant.parent).toEqualTypeOf(); +expectTypeOf(combatant.combat).toEqualTypeOf(); +expectTypeOf(combatant.actor).toEqualTypeOf(); +expectTypeOf(combatant.token).toEqualTypeOf(); +expectTypeOf(combatant.apps).toEqualTypeOf>(); + +// static properties +expectTypeOf(Combatant.create({ name: "Some Combatant" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(Combatant.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(Combatant.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(Combatant.deleteDocuments([])).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/documents/drawing.test-d.ts b/tests/foundry/client/data/documents/drawing.test-d.ts new file mode 100644 index 000000000..ea59800d5 --- /dev/null +++ b/tests/foundry/client/data/documents/drawing.test-d.ts @@ -0,0 +1,5 @@ +import { expectTypeOf } from "vitest"; + +const doc = new DrawingDocument(); + +expectTypeOf(doc.author).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/fog-exploration.test-d.ts b/tests/foundry/client/data/documents/fog-exploration.test-d.ts new file mode 100644 index 000000000..cff05d31c --- /dev/null +++ b/tests/foundry/client/data/documents/fog-exploration.test-d.ts @@ -0,0 +1,21 @@ +import { expectTypeOf } from "vitest"; + +declare const pointSource: PointSource; +declare const scene: Scene; +declare const user: User; + +expectTypeOf(FogExploration.get()).toEqualTypeOf | null>>(); +expectTypeOf(FogExploration.get({})).toEqualTypeOf | null>>(); +expectTypeOf(FogExploration.get({ user })).toEqualTypeOf | null>>(); +expectTypeOf(FogExploration.get({ scene })).toEqualTypeOf | null>>(); +expectTypeOf(FogExploration.get({ scene, user })).toEqualTypeOf | null>>(); +expectTypeOf(FogExploration.get({}, { temporary: true })).toEqualTypeOf< + Promise | null> +>(); + +const fogExploration = new FogExploration(); + +expectTypeOf(fogExploration.explore(pointSource)).toEqualTypeOf(); +expectTypeOf(fogExploration.explore(pointSource, true)).toEqualTypeOf(); + +expectTypeOf(fogExploration.getTexture()).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/folder.test-d.ts b/tests/foundry/client/data/documents/folder.test-d.ts new file mode 100644 index 000000000..1c52b2ae9 --- /dev/null +++ b/tests/foundry/client/data/documents/folder.test-d.ts @@ -0,0 +1,3 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(await Folder.createDialog()).toEqualTypeOf(); diff --git a/test-d/foundry/client/data/documents/item.test-d.ts b/tests/foundry/client/data/documents/item.test-d.ts similarity index 71% rename from test-d/foundry/client/data/documents/item.test-d.ts rename to tests/foundry/client/data/documents/item.test-d.ts index 12448331c..e08bfe66a 100644 --- a/test-d/foundry/client/data/documents/item.test-d.ts +++ b/tests/foundry/client/data/documents/item.test-d.ts @@ -1,4 +1,4 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; interface ArmorDataSourceData { armorValue: number; @@ -52,10 +52,10 @@ declare global { const item = await Item.create({ name: "Mighty Axe of Killing", type: "weapon" }); if (item) { - expectType(item.actor); - expectType(item.img); - expectType(item.isOwned); - expectType(item.transferredEffects); - expectType<"weapon" | "armor">(item.type); - expectType(item.getRollData()); + expectTypeOf(item.actor).toEqualTypeOf(); + expectTypeOf(item.img).toEqualTypeOf(); + expectTypeOf(item.isOwned).toEqualTypeOf(); + expectTypeOf(item.transferredEffects).toEqualTypeOf(); + expectTypeOf(item.type).toEqualTypeOf<"weapon" | "armor">(); + expectTypeOf(item.getRollData()).toEqualTypeOf(); } diff --git a/tests/foundry/client/data/documents/macro.test-d.ts b/tests/foundry/client/data/documents/macro.test-d.ts new file mode 100644 index 000000000..2fce1a057 --- /dev/null +++ b/tests/foundry/client/data/documents/macro.test-d.ts @@ -0,0 +1,30 @@ +import { expectTypeOf } from "vitest"; +import "../../../index"; + +const macro = new Macro({ name: "my macro", scope: "global", type: "script" }); + +// properties and functions added by the concrete `Macro` class +expectTypeOf(macro.isAuthor).toEqualTypeOf(); +expectTypeOf(macro.execute).toEqualTypeOf<(scope?: { actor?: Actor; token?: Token }) => void>(); + +// properties and functions of `ClientDocumentMixin` +expectTypeOf(macro.apps).toEqualTypeOf>(); +expectTypeOf(macro.collection).toEqualTypeOf>(); +expectTypeOf(macro.folder).toEqualTypeOf(); +expectTypeOf(macro.isOwner).toEqualTypeOf(); + +// static properties and functions of `ClientDocumentMixin` +expectTypeOf(Macro.createDialog()).toEqualTypeOf>(); + +// static properties of `BaseMacro` +expectTypeOf(Macro.schema).toEqualTypeOf(); + +// properties of `Document` +expectTypeOf(macro.parent).toEqualTypeOf(); +expectTypeOf(macro.pack).toEqualTypeOf(); + +// static properties of `Document` +expectTypeOf(Macro.create({ name: "Some Macro" })).toEqualTypeOf | undefined>>(); +expectTypeOf(Macro.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(Macro.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(Macro.deleteDocuments([])).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/documents/measured-template.test-d.ts b/tests/foundry/client/data/documents/measured-template.test-d.ts new file mode 100644 index 000000000..fd55932c6 --- /dev/null +++ b/tests/foundry/client/data/documents/measured-template.test-d.ts @@ -0,0 +1,10 @@ +import { expectTypeOf } from "vitest"; + +const doc = new MeasuredTemplateDocument(); + +expectTypeOf(doc.author).toEqualTypeOf(); +// TODO: Modify to TemplateLayer | null once data can be grabbed from CONFIG +expectTypeOf(doc.layer).toEqualTypeOf>(); + +// TODO: Modify to MeasuredTemplateConfig | null once data can be grabbed from CONFIG +expectTypeOf(doc.sheet).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/note.test-d.ts b/tests/foundry/client/data/documents/note.test-d.ts new file mode 100644 index 000000000..793b083e2 --- /dev/null +++ b/tests/foundry/client/data/documents/note.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const doc = new NoteDocument(); + +expectTypeOf(doc.label).toEqualTypeOf(); +expectTypeOf(doc.entry).toEqualTypeOf | undefined>(); diff --git a/tests/foundry/client/data/documents/scene.test-d.ts b/tests/foundry/client/data/documents/scene.test-d.ts new file mode 100644 index 000000000..03c89c65c --- /dev/null +++ b/tests/foundry/client/data/documents/scene.test-d.ts @@ -0,0 +1,29 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - A Scene requires data. +new Scene(); + +// @ts-expect-error - A Scene requires a name. +new Scene({}); + +const scene = new Scene({ name: "My scene" }); +expectTypeOf(scene).toEqualTypeOf(); + +expectTypeOf(scene.dimensions).toEqualTypeOf>(); +expectTypeOf(scene.active).toEqualTypeOf(); +expectTypeOf(scene.img).toEqualTypeOf(); +expectTypeOf(scene.isView).toEqualTypeOf(); +expectTypeOf(scene.journal).toEqualTypeOf(); +expectTypeOf(scene.playlist).toEqualTypeOf(); +expectTypeOf(scene.playlistSound).toEqualTypeOf(); +expectTypeOf(scene.activate()).toEqualTypeOf>(); +expectTypeOf(scene.view()).toEqualTypeOf>(); +expectTypeOf(scene.clone()).toEqualTypeOf>(); +expectTypeOf(scene.prepareBaseData()).toEqualTypeOf(); +expectTypeOf(scene.createThumbnail()).toEqualTypeOf>(); +expectTypeOf(scene.createThumbnail({})).toEqualTypeOf>(); +expectTypeOf(scene.createThumbnail({ img: "path/to/my/img.png" })).toEqualTypeOf< + Promise +>(); +expectTypeOf(scene.createThumbnail({ width: 300 })).toEqualTypeOf>(); +expectTypeOf(scene.createThumbnail({ height: 100 })).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/documents/setting.test-d.ts b/tests/foundry/client/data/documents/setting.test-d.ts new file mode 100644 index 000000000..3b7ee416e --- /dev/null +++ b/tests/foundry/client/data/documents/setting.test-d.ts @@ -0,0 +1,13 @@ +import { expectTypeOf } from "vitest"; + +const setting = new Setting({ key: "foo.bar", value: "bar" }); + +expectTypeOf(Setting.schema).toEqualTypeOf(); +expectTypeOf(setting.key).toEqualTypeOf(); +expectTypeOf(setting.value).toEqualTypeOf(); +expectTypeOf(Setting.create({ key: "foo.bar", value: "bar" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(Setting.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(Setting.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(Setting.deleteDocuments([])).toEqualTypeOf>(); diff --git a/tests/foundry/client/data/documents/table.test-d.ts b/tests/foundry/client/data/documents/table.test-d.ts new file mode 100644 index 000000000..cb1c356f3 --- /dev/null +++ b/tests/foundry/client/data/documents/table.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +const table = new RollTable({ name: "" }); + +// @ts-expect-error - A RollTable requires a name. +new RollTable({}); + +expectTypeOf(table.results.get("testing")).toEqualTypeOf(); + +expectTypeOf(await table.draw()).toEqualTypeOf(); +expectTypeOf((await table.roll()).results[0]).toEqualTypeOf(); +expectTypeOf(table.data.displayRoll).toEqualTypeOf(); + +declare const folder: Folder; +expectTypeOf(await RollTable.fromFolder(folder)).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/tile.test-d.ts b/tests/foundry/client/data/documents/tile.test-d.ts new file mode 100644 index 000000000..434de02a7 --- /dev/null +++ b/tests/foundry/client/data/documents/tile.test-d.ts @@ -0,0 +1,4 @@ +import { expectTypeOf } from "vitest"; + +const doc = new TileDocument(); +expectTypeOf(doc.layer).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/token.test-d.ts b/tests/foundry/client/data/documents/token.test-d.ts new file mode 100644 index 000000000..e0a1063d4 --- /dev/null +++ b/tests/foundry/client/data/documents/token.test-d.ts @@ -0,0 +1,45 @@ +import type EmbeddedCollection from "../../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; +import type { ConfiguredDocumentClass } from "../../../../../src/types/helperTypes.js"; + +import { expectTypeOf } from "vitest"; + +const doc = new TokenDocument({}, { parent: new foundry.documents.BaseScene() }); +expectTypeOf(doc.actor).toEqualTypeOf> | null>(); +expectTypeOf(doc.isOwner).toEqualTypeOf(); +expectTypeOf(doc.isLinked).toEqualTypeOf(); +expectTypeOf(doc.combatant).toEqualTypeOf> | null>(); +expectTypeOf(doc.inCombat).toEqualTypeOf(); +expectTypeOf(doc.clone()).toEqualTypeOf(); +expectTypeOf(doc.clone({}, { save: true })).toEqualTypeOf(); +expectTypeOf(doc.getActor()).toEqualTypeOf> | null>(); +expectTypeOf(doc.modifyActorDocument({ actorLink: true, "lightAnimation.speed": 5 }, {})).toEqualTypeOf< + Promise<[InstanceType> | null]> +>(); + +expectTypeOf(doc.getEmbeddedCollection("Item")).toEqualTypeOf< + EmbeddedCollection, foundry.data.ActorData> +>(); +expectTypeOf(doc.getEmbeddedCollection("ActiveEffect")).toEqualTypeOf< + EmbeddedCollection, foundry.data.ActorData> +>(); + +expectTypeOf( + doc.createActorEmbeddedDocuments("Item", [{ name: "My Item", "effects.": 5 }], { noHook: true }), +).toEqualTypeOf>>>>(); +expectTypeOf( + doc.createActorEmbeddedDocuments("ActiveEffect", [{ icon: "path/to/my/icon", "flags.my-system.something": "6" }], {}), +).toEqualTypeOf>>>>(); + +expectTypeOf( + doc.updateActorEmbeddedDocuments("Item", [{ name: "My Item", "data.something": 5 }], { noHook: true }), +).toEqualTypeOf>>>>(); +expectTypeOf( + doc.updateActorEmbeddedDocuments("ActiveEffect", [{ icon: "path/to/my/icon", "flags.my-system.something": "6" }], {}), +).toEqualTypeOf>>>>(); + +expectTypeOf(doc.deleteActorEmbeddedDocuments("Item", ["BRBEA"], {})).toEqualTypeOf< + Promise>>> +>(); +expectTypeOf(doc.deleteActorEmbeddedDocuments("ActiveEffect", ["BRBEA"], { noHook: true })).toEqualTypeOf< + Promise>>> +>(); diff --git a/tests/foundry/client/data/documents/user.test-d.ts b/tests/foundry/client/data/documents/user.test-d.ts new file mode 100644 index 000000000..6212f1f75 --- /dev/null +++ b/tests/foundry/client/data/documents/user.test-d.ts @@ -0,0 +1,33 @@ +import type { ConfiguredDocumentClass } from "../../../../../src/types/helperTypes"; + +import { assertType, expectTypeOf } from "vitest"; + +const user = new User({ name: "Test" }); + +expectTypeOf(user.active).toEqualTypeOf(); +expectTypeOf(user.targets).toEqualTypeOf(); +expectTypeOf(user.id).toEqualTypeOf(); +expectTypeOf(user.viewedScene).toEqualTypeOf(); +expectTypeOf(user.avatar).toEqualTypeOf(); +expectTypeOf(user.character).toEqualTypeOf< + StoredDocument>> | undefined +>(); +expectTypeOf(user.character).toEqualTypeOf | undefined>(); +assertType>>(user.permissions); +expectTypeOf(user.getHotbarMacros().map((each) => each.macro)).toEqualTypeOf>(); +expectTypeOf(user.getHotbarMacros().map((each) => each.macro)).toEqualTypeOf< + Array> | null> +>(); + +user.assignHotbarMacro(new Macro(), 1); + +expectTypeOf(user.data._id).toEqualTypeOf(); +expectTypeOf(user.data.character).toEqualTypeOf(); +expectTypeOf(user.data.avatar).toEqualTypeOf(); + +// TODO: Modify to ConfiguredDocumentSheet | null once data can be grabbed from CONFIG +expectTypeOf(user.sheet).toEqualTypeOf(); + +expectTypeOf(user.charname).toEqualTypeOf(); +expectTypeOf(user.color).toEqualTypeOf(); +expectTypeOf(user.border).toEqualTypeOf(); diff --git a/tests/foundry/client/data/documents/wall.test-d.ts b/tests/foundry/client/data/documents/wall.test-d.ts new file mode 100644 index 000000000..91e3e18d7 --- /dev/null +++ b/tests/foundry/client/data/documents/wall.test-d.ts @@ -0,0 +1,10 @@ +declare const scene: Scene; + +// @ts-expect-error - A WallDocument requires data. +new WallDocument(); + +// @ts-expect-error - A WallDocument requires a c (coordinates) property. +new WallDocument({}); + +new WallDocument({ c: [0, 0, 0, 0] }); +new WallDocument({ c: [0, 0, 0, 0] }, { parent: scene }); diff --git a/test-d/foundry/client/dice/dice/coin.test-d.ts b/tests/foundry/client/dice/dice/coin.test-d.ts similarity index 100% rename from test-d/foundry/client/dice/dice/coin.test-d.ts rename to tests/foundry/client/dice/dice/coin.test-d.ts diff --git a/test-d/foundry/client/dice/dice/die.test-d.ts b/tests/foundry/client/dice/dice/die.test-d.ts similarity index 100% rename from test-d/foundry/client/dice/dice/die.test-d.ts rename to tests/foundry/client/dice/dice/die.test-d.ts diff --git a/test-d/foundry/client/dice/dice/fate.test-d.ts b/tests/foundry/client/dice/dice/fate.test-d.ts similarity index 100% rename from test-d/foundry/client/dice/dice/fate.test-d.ts rename to tests/foundry/client/dice/dice/fate.test-d.ts diff --git a/tests/foundry/client/dice/roll.test-d.ts b/tests/foundry/client/dice/roll.test-d.ts new file mode 100644 index 000000000..15e4766a7 --- /dev/null +++ b/tests/foundry/client/dice/roll.test-d.ts @@ -0,0 +1,90 @@ +import type { Evaluated, MessageData } from "../../../../src/foundry/client/dice/roll"; + +import { expectTypeOf } from "vitest"; +import "../../index"; + +class CustomRoll extends Roll {} + +CONFIG.Dice.rolls = [CustomRoll, Roll]; + +// Attack with advantage! +const r = new Roll("2d20kh + @prof + @strMod", { prof: 2, strMod: 4 }); + +// create the configured roll instance +expectTypeOf(Roll.create("1d20")).toEqualTypeOf>(); +expectTypeOf(Roll.create("1d20 + @prof", { prof: 2 })).toEqualTypeOf>(); +expectTypeOf(Roll.fromTerms([])).toEqualTypeOf>(); +expectTypeOf(CustomRoll.fromTerms([])).toEqualTypeOf>(); + +// The parsed terms of the roll formula +// [Die, OperatorTerm, NumericTerm, OperatorTerm, NumericTerm] +expectTypeOf(r.terms).toEqualTypeOf(); + +// Execute the roll +type TypeOfR = Roll<{ prof: number; strMod: number }>; +expectTypeOf(r.evaluate({ async: true })).toEqualTypeOf>>(); +expectTypeOf(r.evaluate({ async: false })).toEqualTypeOf>(); +expectTypeOf(r.evaluate()).toEqualTypeOf>>(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true })).toEqualTypeOf>(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true, async: false as boolean })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true, async: false as boolean | undefined })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true, async: false as false | undefined })).toEqualTypeOf< + Evaluated +>(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true, async: false as true | undefined })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf((await r.evaluate()).total).toEqualTypeOf(); + +expectTypeOf(r.roll({ async: true })).toEqualTypeOf>>(); +expectTypeOf(r.roll({ async: false })).toEqualTypeOf>(); +expectTypeOf(r.roll()).toEqualTypeOf>>(); +expectTypeOf(r.roll({ minimize: true, maximize: true })).toEqualTypeOf>(); +expectTypeOf(r.roll({ minimize: true, maximize: true, async: false as boolean })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf(r.roll({ minimize: true, maximize: true, async: false as boolean | undefined })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf(r.roll({ minimize: true, maximize: true, async: false as false | undefined })).toEqualTypeOf< + Evaluated +>(); +expectTypeOf(r.roll({ minimize: true, maximize: true, async: false as true | undefined })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf((await r.roll()).total).toEqualTypeOf(); + +expectTypeOf(r.reroll({ async: true })).toEqualTypeOf>>(); +expectTypeOf(r.reroll({ async: false })).toEqualTypeOf>(); +expectTypeOf(r.reroll()).toEqualTypeOf>>(); +expectTypeOf(r.reroll({ minimize: true, maximize: true })).toEqualTypeOf>(); +expectTypeOf(r.reroll({ minimize: true, maximize: true, async: false as boolean })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf(r.reroll({ minimize: true, maximize: true, async: false as boolean | undefined })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf(r.reroll({ minimize: true, maximize: true, async: false as false | undefined })).toEqualTypeOf< + Evaluated +>(); +expectTypeOf(r.reroll({ minimize: true, maximize: true, async: false as true | undefined })).toEqualTypeOf< + Evaluated | Promise> +>(); +expectTypeOf((await r.reroll()).total).toEqualTypeOf(); + +// The resulting equation after it was rolled +expectTypeOf(r.result).toEqualTypeOf(); // 16 + 2 + 4 + +// The total resulting from the roll +expectTypeOf(r.total).toEqualTypeOf(); // 22 + +expectTypeOf(r.toMessage()).toEqualTypeOf>(); +expectTypeOf(r.toMessage({}, { create: true })).toEqualTypeOf>(); +expectTypeOf(r.toMessage({}, { create: false })).toEqualTypeOf>(); +expectTypeOf(r.toMessage({}, { create: false as boolean })).toEqualTypeOf< + Promise | MessageData<{}> +>(); diff --git a/tests/foundry/client/dice/term.test-d.ts b/tests/foundry/client/dice/term.test-d.ts new file mode 100644 index 000000000..0baea1573 --- /dev/null +++ b/tests/foundry/client/dice/term.test-d.ts @@ -0,0 +1,25 @@ +import { expectTypeOf } from "vitest"; +import "../../index"; + +class CustomRollTerm extends RollTerm { + someProperty = 42; +} + +const r = new CustomRollTerm(); + +expectTypeOf(r.evaluate({ async: true })).toEqualTypeOf>(); +expectTypeOf(r.evaluate({ async: false })).toEqualTypeOf(); +expectTypeOf(r.evaluate()).toEqualTypeOf(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true })).toEqualTypeOf(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true, async: false as boolean })).toEqualTypeOf< + CustomRollTerm | Promise +>(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true, async: false as boolean | undefined })).toEqualTypeOf< + CustomRollTerm | Promise +>(); +expectTypeOf( + r.evaluate({ minimize: true, maximize: true, async: false as false | undefined }), +).toEqualTypeOf(); +expectTypeOf(r.evaluate({ minimize: true, maximize: true, async: false as true | undefined })).toEqualTypeOf< + CustomRollTerm | Promise +>(); diff --git a/tests/foundry/client/game.test-d.ts b/tests/foundry/client/game.test-d.ts new file mode 100644 index 000000000..a84753c06 --- /dev/null +++ b/tests/foundry/client/game.test-d.ts @@ -0,0 +1,64 @@ +import { expectTypeOf, assertType } from "vitest"; + +declare const aGame: Game; + +expectTypeOf(aGame.combats).toEqualTypeOf(); +expectTypeOf(aGame.i18n).toEqualTypeOf(); +expectTypeOf(aGame.settings).toEqualTypeOf(); + +declare global { + interface ModuleConfig { + "optional-api-module": { + api: { + testApi: (value: string) => boolean; + }; + }; + "api-module-with-optional-props": { + always: string; + maybe?: number; + }; + "required-api-module": { + hooks: { + triggerDialog: (value: number) => void; + }; + }; + } + interface RequiredModules { + "required-module": true; + "required-api-module": true; + } +} +/** Convenance type for test, might be worth while moving inside the types */ +type Module = Game.ModuleData; + +assertType(aGame.modules.get("optional-module")); + +expectTypeOf(aGame.modules.get("required-module")).toEqualTypeOf(); + +const optionalApiModule = aGame.modules.get("optional-api-module"); +if (optionalApiModule) { + expectTypeOf(optionalApiModule.api).toEqualTypeOf(); + if (optionalApiModule.active) { + expectTypeOf(optionalApiModule.active).toEqualTypeOf(); + expectTypeOf(optionalApiModule.api.testApi).toEqualTypeOf<(value: string) => boolean>(); + } else { + expectTypeOf(optionalApiModule.active).toEqualTypeOf(); + expectTypeOf(optionalApiModule.api).toEqualTypeOf(); + } +} + +const moduleOptionalProps = aGame.modules.get("api-module-with-optional-props"); +if (moduleOptionalProps) { + expectTypeOf(moduleOptionalProps.always).toEqualTypeOf(); + expectTypeOf(moduleOptionalProps.maybe).toEqualTypeOf(); + if (moduleOptionalProps.active) { + expectTypeOf(moduleOptionalProps.always).toEqualTypeOf(); + expectTypeOf(moduleOptionalProps.maybe).toEqualTypeOf(); + // @ts-expect-error - number would the entirely wrong type. + expectTypeOf(moduleOptionalProps.maybe).toEqualTypeOf(); + } +} +const requiredApiModule = aGame.modules.get("required-api-module"); + +expectTypeOf(requiredApiModule).toEqualTypeOf(); +expectTypeOf(requiredApiModule.hooks.triggerDialog(5)).toEqualTypeOf(); diff --git a/tests/foundry/client/head.test-d.ts b/tests/foundry/client/head.test-d.ts new file mode 100644 index 000000000..f7d122638 --- /dev/null +++ b/tests/foundry/client/head.test-d.ts @@ -0,0 +1,4 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(game).toEqualTypeOf(); +expectTypeOf(ui.menu).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/board.test-d.ts b/tests/foundry/client/pixi/board.test-d.ts new file mode 100644 index 000000000..a25db1287 --- /dev/null +++ b/tests/foundry/client/pixi/board.test-d.ts @@ -0,0 +1,32 @@ +import { assertType, expectTypeOf } from "vitest"; + +type TilesLayer = unknown; // FIXME: remove when TilesLayer is typed + +const myCanvas = new Canvas(); +assertType>>>(Canvas.layers); +expectTypeOf(myCanvas.draw(new Scene({ name: "My Scene" }))).toEqualTypeOf>(); + +expectTypeOf(myCanvas.getLayerByEmbeddedName("AmbientLight")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("AmbientSound")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("Drawing")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("Note")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("MeasuredTemplate")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("Tile")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("Token")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("Wall")).toEqualTypeOf(); +expectTypeOf(myCanvas.getLayerByEmbeddedName("any-string")).toEqualTypeOf(); + +expectTypeOf(myCanvas.animatePan()).toEqualTypeOf>(); +expectTypeOf(myCanvas.animatePan({})).toEqualTypeOf>(); +expectTypeOf(myCanvas.animatePan({ x: 100, y: 100, scale: 1, duration: 250, speed: 10 })).toEqualTypeOf< + Promise +>(); + +expectTypeOf(myCanvas.recenter()).toEqualTypeOf>(); +expectTypeOf(myCanvas.recenter({})).toEqualTypeOf>(); +expectTypeOf(myCanvas.recenter({ x: null, y: null, scale: null })).toEqualTypeOf>(); +expectTypeOf(myCanvas.recenter({ x: 100, y: 100, scale: 1 })).toEqualTypeOf>(); + +expectTypeOf( + myCanvas.addPendingOperation("Canvas.recenter", myCanvas.recenter, myCanvas, { x: 100, y: 100, scale: 1 }), +).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/core/containers/cached-container.test-d.ts b/tests/foundry/client/pixi/core/containers/cached-container.test-d.ts new file mode 100644 index 000000000..99cfdf186 --- /dev/null +++ b/tests/foundry/client/pixi/core/containers/cached-container.test-d.ts @@ -0,0 +1,16 @@ +import { assertType, expectTypeOf } from "vitest"; + +const container = new CachedContainer(); +assertType(container); +expectTypeOf(container.renderTexture).toEqualTypeOf(); +expectTypeOf(container.clearColor).toEqualTypeOf<[number, number, number, number]>(); +expectTypeOf(container.displayed).toEqualTypeOf(); +expectTypeOf(container.destroy()).toEqualTypeOf(); +expectTypeOf( + container.destroy({ + children: false, + texture: false, + baseTexture: false, + }), +).toEqualTypeOf(); +expectTypeOf(container.render(new PIXI.Renderer())).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/core/interaction/targets.test-d.ts b/tests/foundry/client/pixi/core/interaction/targets.test-d.ts new file mode 100644 index 000000000..36b512d6b --- /dev/null +++ b/tests/foundry/client/pixi/core/interaction/targets.test-d.ts @@ -0,0 +1,11 @@ +import { expectTypeOf } from "vitest"; + +declare const user: User; +declare const token: Token; + +const targets = new UserTargets(user); +expectTypeOf(targets.user).toEqualTypeOf(); +expectTypeOf(targets.ids).toEqualTypeOf(); +expectTypeOf(targets.add(token)).toEqualTypeOf(); +expectTypeOf(targets.clear()).toEqualTypeOf(); +expectTypeOf(targets.delete(token)).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/core/loader.test-d.ts b/tests/foundry/client/pixi/core/loader.test-d.ts new file mode 100644 index 000000000..ce545db43 --- /dev/null +++ b/tests/foundry/client/pixi/core/loader.test-d.ts @@ -0,0 +1,11 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(srcExists("path/to/texture")).toEqualTypeOf>(); + +expectTypeOf(getTexture("path/to/texture")).toEqualTypeOf(); + +expectTypeOf(loadTexture("path/to/texture")).toEqualTypeOf>(); +expectTypeOf(loadTexture("path/to/texture", {})).toEqualTypeOf>(); +expectTypeOf(loadTexture("path/to/texture", { fallback: "path/to/another/texture" })).toEqualTypeOf< + Promise +>(); diff --git a/tests/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts b/tests/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts new file mode 100644 index 000000000..ac24a8801 --- /dev/null +++ b/tests/foundry/client/pixi/core/shapes/normalized-rectangle.test-d.ts @@ -0,0 +1,7 @@ +import { assertType, expectTypeOf } from "vitest"; + +const rectangle = new NormalizedRectangle(100, 300, 500, 400); +assertType(rectangle); +expectTypeOf(rectangle.rotate(0.5)).toEqualTypeOf(); + +expectTypeOf(NormalizedRectangle.fromRotation(100, 300, 200, 100, 0.5)).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/controls/cursor.test-d.ts b/tests/foundry/client/pixi/layers/controls/cursor.test-d.ts new file mode 100644 index 000000000..0a33a5549 --- /dev/null +++ b/tests/foundry/client/pixi/layers/controls/cursor.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +declare const user: User; + +const cursor = new Cursor(user); +expectTypeOf(cursor.draw(user)).toEqualTypeOf(); +expectTypeOf(cursor.destroy()).toEqualTypeOf(); +expectTypeOf(cursor.destroy({})).toEqualTypeOf(); +expectTypeOf(cursor.destroy({ children: true, texture: true, baseTexture: true })).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/controls/door.test-d.ts b/tests/foundry/client/pixi/layers/controls/door.test-d.ts new file mode 100644 index 000000000..1b7b9b4c4 --- /dev/null +++ b/tests/foundry/client/pixi/layers/controls/door.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +declare const wall: Wall; + +// @ts-expect-error - A DoorControl requires a wall. +new DoorControl(); + +const control = new DoorControl(wall); +expectTypeOf(control.wall).toEqualTypeOf(); +expectTypeOf(control.draw()).toEqualTypeOf>(); +expectTypeOf(control.bg).toEqualTypeOf(); +expectTypeOf(control.icon).toEqualTypeOf(); +expectTypeOf(control.border).toEqualTypeOf(); +expectTypeOf(control.reposition()).toEqualTypeOf(); +expectTypeOf(control.isVisible).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/controls/ruler.test-d.ts b/tests/foundry/client/pixi/layers/controls/ruler.test-d.ts new file mode 100644 index 000000000..a44ad57ac --- /dev/null +++ b/tests/foundry/client/pixi/layers/controls/ruler.test-d.ts @@ -0,0 +1,27 @@ +import { expectTypeOf } from "vitest"; + +if (game instanceof Game) { + expectTypeOf(new Ruler(undefined)).toEqualTypeOf(); + expectTypeOf(new Ruler(game.user, { color: null })).toEqualTypeOf(); + expectTypeOf(new Ruler(game.user, { color: 0x32f4e2 })).toEqualTypeOf(); +} + +const ruler = new Ruler(); +expectTypeOf(ruler.user).toEqualTypeOf(); +expectTypeOf(ruler.name).toEqualTypeOf(); +expectTypeOf(ruler.color).toEqualTypeOf(); +expectTypeOf(ruler.waypoints).toEqualTypeOf(); +expectTypeOf(ruler.destination).toEqualTypeOf(); +expectTypeOf(ruler.ruler).toEqualTypeOf(); +expectTypeOf(ruler.labels).toEqualTypeOf(); +expectTypeOf(Ruler.STATES).toEqualTypeOf<{ INACTIVE: 0; STARTING: 1; MEASURING: 2; MOVING: 3 }>(); +expectTypeOf(ruler.active).toEqualTypeOf(); + +expectTypeOf(ruler.measure(new PIXI.Point())).toEqualTypeOf>(); +expectTypeOf(ruler.measure({ x: 10, y: 10 }, {})).toEqualTypeOf>(); +expectTypeOf(ruler.measure({ x: 10, y: 10 }, { gridSpaces: true })).toEqualTypeOf>(); + +expectTypeOf(ruler.moveToken()).toEqualTypeOf>(); +expectTypeOf(ruler.clear()).toEqualTypeOf(); +expectTypeOf(ruler.toJSON()).toEqualTypeOf(); +expectTypeOf(ruler.update(ruler.toJSON())).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/drawings.test-d.ts b/tests/foundry/client/pixi/layers/drawings.test-d.ts new file mode 100644 index 000000000..be3c65068 --- /dev/null +++ b/tests/foundry/client/pixi/layers/drawings.test-d.ts @@ -0,0 +1,17 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(DrawingsLayer.documentName).toEqualTypeOf<"Drawing">(); +expectTypeOf(DrawingsLayer.instance).toEqualTypeOf(); +expectTypeOf(DrawingsLayer.layerOptions).toEqualTypeOf(); +expectTypeOf(DrawingsLayer.layerOptions.name).toEqualTypeOf<"drawings">(); +expectTypeOf(DrawingsLayer.layerOptions.objectClass).toEqualTypeOf(); +expectTypeOf(DrawingsLayer.DEFAULT_CONFIG_SETTING).toEqualTypeOf<"defaultDrawingConfig">(); + +const layer = new DrawingsLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.options).toEqualTypeOf(); +expectTypeOf(layer.options.name).toEqualTypeOf<"drawings">(); +expectTypeOf(layer.gridPrecision).toEqualTypeOf<16 | 8 | 0>(); +expectTypeOf(layer.hud).toEqualTypeOf(); +expectTypeOf(layer.configureDefault()).toEqualTypeOf(); +expectTypeOf(layer.deactivate()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/effects.test-d.ts b/tests/foundry/client/pixi/layers/effects.test-d.ts new file mode 100644 index 000000000..c85bafbfa --- /dev/null +++ b/tests/foundry/client/pixi/layers/effects.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(WeatherLayer.instance).toEqualTypeOf(); +expectTypeOf(WeatherLayer.layerOptions).toEqualTypeOf(); +expectTypeOf(WeatherLayer.layerOptions.name).toEqualTypeOf<"effects">(); + +const layer = new WeatherLayer(); +expectTypeOf(layer.options.name).toEqualTypeOf<"effects">(); +expectTypeOf(layer.weather).toEqualTypeOf(); +expectTypeOf(layer.weatherEffect).toEqualTypeOf(); +expectTypeOf(layer.emitters).toEqualTypeOf(); +expectTypeOf(layer.weatherOcclusionFilter).toEqualTypeOf(); +expectTypeOf(layer.tearDown()).toEqualTypeOf>(); +expectTypeOf(layer.draw()).toEqualTypeOf>(); +expectTypeOf(layer.drawWeather()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/grid.test-d.ts b/tests/foundry/client/pixi/layers/grid.test-d.ts new file mode 100644 index 000000000..b09e9c960 --- /dev/null +++ b/tests/foundry/client/pixi/layers/grid.test-d.ts @@ -0,0 +1,56 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(GridLayer.instance).toEqualTypeOf(); +expectTypeOf(GridLayer.layerOptions).toEqualTypeOf(); +expectTypeOf(GridLayer.layerOptions.name).toEqualTypeOf<"grid">(); + +const layer = new GridLayer(); +expectTypeOf(layer.options.name).toEqualTypeOf<"grid">(); +expectTypeOf(layer.grid).toEqualTypeOf(); +expectTypeOf(layer.highlight).toEqualTypeOf(); +expectTypeOf(layer.highlightLayers).toEqualTypeOf>(); +expectTypeOf(layer.type).toEqualTypeOf(); +expectTypeOf(layer.size).toEqualTypeOf(); +expectTypeOf(layer.w).toEqualTypeOf(); +expectTypeOf(layer.h).toEqualTypeOf(); +expectTypeOf(layer.isHex).toEqualTypeOf(); +expectTypeOf(layer.draw()).toEqualTypeOf>(); +expectTypeOf(layer.draw({})).toEqualTypeOf>(); +expectTypeOf(layer.draw({ type: null, dimensions: null, gridColor: null, gridAlpha: null })).toEqualTypeOf< + Promise +>(); +expectTypeOf(layer.draw({ type: foundry.CONST.GRID_TYPES.GRIDLESS })).toEqualTypeOf>(); +expectTypeOf(layer.draw({ dimensions: (canvas as Canvas).dimensions })).toEqualTypeOf>(); +expectTypeOf(layer.draw({ gridColor: "#000000" })).toEqualTypeOf>(); +expectTypeOf(layer.draw({ gridColor: 0x000000 })).toEqualTypeOf>(); +expectTypeOf(layer.draw({ gridAlpha: 0.2 })).toEqualTypeOf>(); +expectTypeOf(layer.getSnappedPosition(10, 100)).toEqualTypeOf<{ x: number; y: number }>(); +expectTypeOf(layer.getSnappedPosition(10, 100, 2)).toEqualTypeOf<{ x: number; y: number }>(); +expectTypeOf(layer.getTopLeft(8, 17)).toEqualTypeOf<[number, number]>(); +expectTypeOf(layer.getCenter(8, 17)).toEqualTypeOf<[number, number]>(); +expectTypeOf(layer.measureDistance({ x: 8, y: 17 }, { x: 1100, y: 1200 })).toEqualTypeOf(); +expectTypeOf(layer.measureDistances([{ ray: new Ray({ x: 8, y: 17 }, { x: 1100, y: 1200 }) }])).toEqualTypeOf< + number[] +>(); +expectTypeOf(layer.measureDistances([{ ray: new Ray({ x: 8, y: 17 }, { x: 1100, y: 1200 }) }], {})).toEqualTypeOf< + number[] +>(); +expectTypeOf( + layer.measureDistances([{ ray: new Ray({ x: 8, y: 17 }, { x: 1100, y: 1200 }) }], { gridSpaces: true }), +).toEqualTypeOf(); +expectTypeOf(layer.addHighlightLayer("some")).toEqualTypeOf(); +expectTypeOf(layer.getHighlightLayer("some")).toEqualTypeOf(); +expectTypeOf(layer.clearHighlightLayer("some")).toEqualTypeOf(); +expectTypeOf(layer.destroyHighlightLayer("some")).toEqualTypeOf(); +expectTypeOf(layer.highlightPosition("some")).toEqualTypeOf(); +expectTypeOf( + layer.highlightPosition("some", { + x: 10, + y: 100, + color: 0x33bbff, + border: null, + alpha: 0.25, + shape: new PIXI.Polygon(), + }), +).toEqualTypeOf(); +expectTypeOf(layer.isNeighbor(0, 1, 2, 3)).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/grid/highlight.test-d.ts b/tests/foundry/client/pixi/layers/grid/highlight.test-d.ts new file mode 100644 index 000000000..d1043bdd7 --- /dev/null +++ b/tests/foundry/client/pixi/layers/grid/highlight.test-d.ts @@ -0,0 +1,11 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(new GridHighlight("")).toEqualTypeOf(); + +const grid = new GridHighlight("", new PIXI.GraphicsGeometry()); +expectTypeOf(grid.name).toEqualTypeOf(); +expectTypeOf(grid.positions).toEqualTypeOf>(); +expectTypeOf(grid.highlight(100, 100)).toEqualTypeOf(); +expectTypeOf(grid.clear()).toEqualTypeOf(); +expectTypeOf(grid.destroy()).toEqualTypeOf(); +expectTypeOf(grid.destroy({ children: true, texture: true, baseTexture: true })).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/lighting.test-d.ts b/tests/foundry/client/pixi/layers/lighting.test-d.ts new file mode 100644 index 000000000..8b3dd9a2f --- /dev/null +++ b/tests/foundry/client/pixi/layers/lighting.test-d.ts @@ -0,0 +1,14 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(LightingLayer.instance).toEqualTypeOf(); +expectTypeOf(LightingLayer.layerOptions.objectClass).toEqualTypeOf(); + +const layer = new LightingLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.options).toEqualTypeOf(); +expectTypeOf(layer.options.name).toEqualTypeOf<"lighting">(); + +expectTypeOf(layer.animateDarkness()).toEqualTypeOf>(); +expectTypeOf(layer.animateDarkness(1.0)).toEqualTypeOf>(); +expectTypeOf(layer.animateDarkness(1.0, {})).toEqualTypeOf>(); +expectTypeOf(layer.animateDarkness(1.0, { duration: 10000 })).toEqualTypeOf>(); diff --git a/tests/foundry/client/pixi/layers/map.test-d.ts b/tests/foundry/client/pixi/layers/map.test-d.ts new file mode 100644 index 000000000..5199e3045 --- /dev/null +++ b/tests/foundry/client/pixi/layers/map.test-d.ts @@ -0,0 +1,47 @@ +import type EmbeddedCollection from "../../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; + +import { expectTypeOf } from "vitest"; + +expectTypeOf(MapLayer.documentName).toEqualTypeOf<"Tile">(); +expectTypeOf(MapLayer.layerOptions).toEqualTypeOf(); +expectTypeOf(MapLayer.layerOptions.name).toEqualTypeOf<"background" | "foreground">(); +expectTypeOf(MapLayer.layerOptions.objectClass).toEqualTypeOf(); + +expectTypeOf(new MapLayer()).toEqualTypeOf(); +expectTypeOf(new MapLayer({ bgPath: "/path/to/an/image.png", level: 1 })).toEqualTypeOf(); + +const layer = new MapLayer(); +expectTypeOf(layer.options).toEqualTypeOf>(); +expectTypeOf(layer.options.name).toEqualTypeOf<"background">(); +expectTypeOf(layer.level).toEqualTypeOf(); +expectTypeOf(layer.bgPath).toEqualTypeOf(); +expectTypeOf(layer.bg).toEqualTypeOf(); +expectTypeOf(layer.bgSource).toEqualTypeOf(); +expectTypeOf(layer.hud).toEqualTypeOf(); +expectTypeOf(layer.isVideo).toEqualTypeOf(); +expectTypeOf(layer.tiles).toEqualTypeOf(); +expectTypeOf(layer.deactivate()).toEqualTypeOf(); +expectTypeOf(layer.tearDown()).toEqualTypeOf>(); +expectTypeOf(layer.draw()).toEqualTypeOf>(); + +expectTypeOf(BackgroundLayer.layerOptions).toEqualTypeOf>(); + +const bgLayer = new BackgroundLayer(); +expectTypeOf(bgLayer.options.name).toEqualTypeOf<"background">(); +expectTypeOf(bgLayer.getDocuments()).toEqualTypeOf< + EmbeddedCollection | TileDocument[] +>(); +expectTypeOf(bgLayer.storeHistory("create", new TileDocument().data)).toEqualTypeOf(); +expectTypeOf(bgLayer.storeHistory("update", new TileDocument().data)).toEqualTypeOf(); +expectTypeOf(bgLayer.storeHistory("delete", new TileDocument().data)).toEqualTypeOf(); + +// @ts-expect-error - "new" is not a valid history type. +bgLayer.storeHistory("new", new TileDocument().data); + +expectTypeOf(ForegroundLayer.layerOptions).toEqualTypeOf>(); + +const fgLayer = new ForegroundLayer(); +expectTypeOf(fgLayer.options.name).toEqualTypeOf<"foreground">(); +expectTypeOf(fgLayer.getDocuments()).toEqualTypeOf< + EmbeddedCollection | TileDocument[] +>(); diff --git a/tests/foundry/client/pixi/layers/notes.test-d.ts b/tests/foundry/client/pixi/layers/notes.test-d.ts new file mode 100644 index 000000000..f7842f8b0 --- /dev/null +++ b/tests/foundry/client/pixi/layers/notes.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(NotesLayer.instance).toEqualTypeOf(); +expectTypeOf(NotesLayer.layerOptions.objectClass).toEqualTypeOf(); + +const layer = new NotesLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.options).toEqualTypeOf(); +expectTypeOf(layer.options.name).toEqualTypeOf<"notes">(); diff --git a/tests/foundry/client/pixi/layers/sounds.test-d.ts b/tests/foundry/client/pixi/layers/sounds.test-d.ts new file mode 100644 index 000000000..e7b191671 --- /dev/null +++ b/tests/foundry/client/pixi/layers/sounds.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(SoundsLayer.instance).toEqualTypeOf(); +expectTypeOf(SoundsLayer.layerOptions.objectClass).toEqualTypeOf(); + +const layer = new SoundsLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.options).toEqualTypeOf(); +expectTypeOf(layer.options.name).toEqualTypeOf<"sounds">(); diff --git a/tests/foundry/client/pixi/layers/templates.test-d.ts b/tests/foundry/client/pixi/layers/templates.test-d.ts new file mode 100644 index 000000000..e44d506cc --- /dev/null +++ b/tests/foundry/client/pixi/layers/templates.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(TemplateLayer.documentName).toEqualTypeOf<"MeasuredTemplate">(); +expectTypeOf(TemplateLayer.instance).toEqualTypeOf(); +expectTypeOf(TemplateLayer.layerOptions).toEqualTypeOf(); +expectTypeOf(TemplateLayer.layerOptions.name).toEqualTypeOf<"templates">(); +expectTypeOf(TemplateLayer.layerOptions.objectClass).toEqualTypeOf(); +expectTypeOf(TemplateLayer.registerSettings()).toEqualTypeOf(); + +const layer = new TemplateLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.options).toEqualTypeOf(); +expectTypeOf(layer.options.name).toEqualTypeOf<"templates">(); +expectTypeOf(layer.activate()).toEqualTypeOf(); +expectTypeOf(layer.deactivate()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/layers/tokens.test-d.ts b/tests/foundry/client/pixi/layers/tokens.test-d.ts new file mode 100644 index 000000000..09c096be6 --- /dev/null +++ b/tests/foundry/client/pixi/layers/tokens.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(TokenLayer.instance).toEqualTypeOf(); +expectTypeOf(TokenLayer.layerOptions.objectClass).toEqualTypeOf(); + +const layer = new TokenLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.options).toEqualTypeOf(); +expectTypeOf(layer.options.name).toEqualTypeOf<"tokens">(); diff --git a/tests/foundry/client/pixi/layers/walls.test-d.ts b/tests/foundry/client/pixi/layers/walls.test-d.ts new file mode 100644 index 000000000..0289ac0c3 --- /dev/null +++ b/tests/foundry/client/pixi/layers/walls.test-d.ts @@ -0,0 +1,36 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(WallsLayer.instance).toEqualTypeOf(); +expectTypeOf(WallsLayer.layerOptions.objectClass).toEqualTypeOf(); + +const layer = new WallsLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.options).toEqualTypeOf(); +expectTypeOf(layer.options.name).toEqualTypeOf<"walls">(); + +expectTypeOf(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }))).toEqualTypeOf(); +expectTypeOf( + layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { type: "move" }), +).toEqualTypeOf(); +expectTypeOf( + layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { type: "sight" }), +).toEqualTypeOf(); +expectTypeOf( + layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { type: "sound" }), +).toEqualTypeOf(); +expectTypeOf( + layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { mode: "any" }), +).toEqualTypeOf(); + +expectTypeOf(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { mode: "closest" })).toEqualTypeOf< + PolygonVertex | boolean +>(); +expectTypeOf(layer.checkCollision(new Ray({ x: 100, y: 100 }, { x: 100, y: 100 }), { mode: "all" })).toEqualTypeOf< + PolygonVertex[] | boolean +>(); + +expectTypeOf(layer.pasteObjects({ x: 900, y: 800 })).toEqualTypeOf>(); +expectTypeOf(layer.pasteObjects({ x: 900, y: 800 }, {})).toEqualTypeOf>(); +expectTypeOf(layer.pasteObjects({ x: 900, y: 800 }, { hidden: true, snap: true })).toEqualTypeOf< + Promise +>(); diff --git a/tests/foundry/client/pixi/perception/clockwise-sweep.test-d.ts b/tests/foundry/client/pixi/perception/clockwise-sweep.test-d.ts new file mode 100644 index 000000000..0b7cb653e --- /dev/null +++ b/tests/foundry/client/pixi/perception/clockwise-sweep.test-d.ts @@ -0,0 +1,38 @@ +import { expectTypeOf } from "vitest"; + +const someRay = new Ray({ x: 0, y: 0 }, { x: 0, y: 0 }); +const somePolygonRay: PolygonRay = someRay as PolygonRay; +somePolygonRay.result = new CollisionResult(); + +expectTypeOf(ClockwiseSweepPolygon.getRayCollisions(somePolygonRay, { mode: "any" })).toEqualTypeOf(); +expectTypeOf( + ClockwiseSweepPolygon.getRayCollisions(somePolygonRay, { mode: "closest" }), +).toEqualTypeOf(); +expectTypeOf(ClockwiseSweepPolygon.getRayCollisions(somePolygonRay, { mode: "all" })).toEqualTypeOf(); + +declare const initializedConfig: ClockwiseSweepPolygon.InitializedConfig; +expectTypeOf(initializedConfig.hasLimitedRadius).toEqualTypeOf(); +expectTypeOf(initializedConfig.radius).toEqualTypeOf(); +expectTypeOf(initializedConfig.radius2).toEqualTypeOf(); +expectTypeOf(initializedConfig.radiusE).toEqualTypeOf(); +expectTypeOf(initializedConfig.aMin).toEqualTypeOf(); +expectTypeOf(initializedConfig.aMax).toEqualTypeOf(); +expectTypeOf(initializedConfig.angle).toEqualTypeOf(); +expectTypeOf(initializedConfig.rotation).toEqualTypeOf(); +expectTypeOf(initializedConfig.hasLimitedAngle).toEqualTypeOf(); +expectTypeOf(initializedConfig.density).toEqualTypeOf(); +expectTypeOf(initializedConfig.rMax).toEqualTypeOf(); +expectTypeOf(initializedConfig.rMin).toEqualTypeOf(); +declare const limitedAngleConfig: ClockwiseSweepPolygon.LimitedAngleConfig; +expectTypeOf(limitedAngleConfig.hasLimitedRadius).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.radius).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.radius2).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.radiusE).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.aMin).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.aMax).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.angle).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.rotation).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.hasLimitedAngle).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.density).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.rMax).toEqualTypeOf(); +expectTypeOf(limitedAngleConfig.rMin).toEqualTypeOf(); diff --git a/test-d/foundry/client/pixi/perception/perception-manager.test-d.ts b/tests/foundry/client/pixi/perception/perception-manager.test-d.ts similarity index 55% rename from test-d/foundry/client/pixi/perception/perception-manager.test-d.ts rename to tests/foundry/client/pixi/perception/perception-manager.test-d.ts index 4a04c5c45..9dfcdab2b 100644 --- a/test-d/foundry/client/pixi/perception/perception-manager.test-d.ts +++ b/tests/foundry/client/pixi/perception/perception-manager.test-d.ts @@ -1,47 +1,47 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; const manager = new PerceptionManager(); -expectType(manager.params); +expectTypeOf(manager.params).toEqualTypeOf(); -expectType(manager.cancel()); +expectTypeOf(manager.cancel()).toEqualTypeOf(); -expectType(manager.schedule()); -expectType(manager.schedule({})); -expectType( +expectTypeOf(manager.schedule()).toEqualTypeOf(); +expectTypeOf(manager.schedule({})).toEqualTypeOf(); +expectTypeOf( manager.schedule({ lighting: { initialize: true }, sight: { initialize: false }, sounds: { initialize: false }, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( manager.schedule({ lighting: { initialize: true, refresh: true }, sight: { initialize: false, refresh: true, skipUpdateFog: true, forceUpdateFog: true }, sounds: { initialize: false, refresh: false, fade: true }, foreground: { refresh: true }, }), -); +).toEqualTypeOf(); -expectType(manager.update()); -expectType(manager.update({})); -expectType( +expectTypeOf(manager.update()).toEqualTypeOf(); +expectTypeOf(manager.update({})).toEqualTypeOf(); +expectTypeOf( manager.update({ lighting: { initialize: true }, sight: { initialize: false }, sounds: { initialize: false }, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( manager.update({ lighting: { initialize: true, refresh: true }, sight: { initialize: false, refresh: true, skipUpdateFog: true, forceUpdateFog: true }, sounds: { initialize: false, refresh: false, fade: true }, foreground: { refresh: true }, }), -); +).toEqualTypeOf(); -expectType(manager.initialize()); +expectTypeOf(manager.initialize()).toEqualTypeOf(); -expectType(manager.refresh()); +expectTypeOf(manager.refresh()).toEqualTypeOf(); diff --git a/test-d/foundry/client/pixi/placeable.test-d.ts b/tests/foundry/client/pixi/placeable.test-d.ts similarity index 80% rename from test-d/foundry/client/pixi/placeable.test-d.ts rename to tests/foundry/client/pixi/placeable.test-d.ts index e154a5b87..65cf32893 100644 --- a/test-d/foundry/client/pixi/placeable.test-d.ts +++ b/tests/foundry/client/pixi/placeable.test-d.ts @@ -1,6 +1,6 @@ import type { ConfiguredDocumentClass } from "../../../../src/types/helperTypes"; -import { expectAssignable, expectType } from "tsd"; +import { assertType, expectTypeOf } from "vitest"; import "../../../../index"; import { Document } from "../../../../src/foundry/common/abstract/module.mjs.js"; @@ -33,9 +33,9 @@ class OnePlaceable extends PlaceableObject { } const placeable = new OnePlaceable(new EmbeddedInSceneDocument()); -expectAssignable>(placeable.document); -expectType(placeable.document); -expectType(placeable.sheet); +assertType>(placeable.document); +expectTypeOf(placeable.document).toEqualTypeOf(); +expectTypeOf(placeable.sheet).toEqualTypeOf(); class ConcretePlaceableObject extends PlaceableObject { get bounds(): NormalizedRectangle { @@ -48,6 +48,6 @@ class ConcretePlaceableObject extends PlaceableObject { return this; } } -expectType | null>( +expectTypeOf( new ConcretePlaceableObject(new EmbeddedInSceneDocument()).mouseInteractionManager, -); +).toEqualTypeOf | null>(); diff --git a/tests/foundry/client/pixi/placeables.test-d.ts b/tests/foundry/client/pixi/placeables.test-d.ts new file mode 100644 index 000000000..ff510451e --- /dev/null +++ b/tests/foundry/client/pixi/placeables.test-d.ts @@ -0,0 +1,107 @@ +import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; +import { expectTypeOf } from "vitest"; + +declare class SomeLightLayer extends PlaceablesLayer<"AmbientLight", PlaceablesLayer.LayerOptions<"AmbientLight">> {} + +expectTypeOf(SomeLightLayer.instance).toEqualTypeOf(); +expectTypeOf(SomeLightLayer.layerOptions).toEqualTypeOf>(); +expectTypeOf(SomeLightLayer.layerOptions.objectClass).toEqualTypeOf(); // TODO: Can this be typed to DocumentConstructor? +expectTypeOf(PlaceablesLayer.documentName).toEqualTypeOf< + "AmbientLight" | "AmbientSound" | "Drawing" | "MeasuredTemplate" | "Note" | "Tile" | "Token" | "Wall" +>(); +expectTypeOf(PlaceablesLayer.placeableClass).toEqualTypeOf>(); + +const layer = new SomeLightLayer(); +expectTypeOf(layer.options.objectClass).toEqualTypeOf(); +expectTypeOf(layer.objects).toEqualTypeOf(); +expectTypeOf(layer.preview).toEqualTypeOf(); +expectTypeOf(layer.history).toEqualTypeOf< + Array<{ type: "create" | "update" | "delete"; data: Array }> +>(); +expectTypeOf(layer.quadtree).toEqualTypeOf | null>(); +expectTypeOf(layer.documentCollection).toEqualTypeOf | null>(); +expectTypeOf(layer.gridPrecision).toEqualTypeOf(); +expectTypeOf(layer.hud).toEqualTypeOf | null>(); +expectTypeOf(layer.placeables).toEqualTypeOf(); +expectTypeOf(layer.controlled).toEqualTypeOf(); +expectTypeOf(layer.getDocuments()).toEqualTypeOf< + EmbeddedCollection | AmbientLightDocument[] +>(); +expectTypeOf(layer.draw()).toEqualTypeOf>(); +expectTypeOf(layer.createObject(new AmbientLightDocument())).toEqualTypeOf(); + +// @ts-expect-error - A LightLayer needs an AmbientLightDocument. +layer.createObject({}); + +// @ts-expect-error - A LightLayer needs an AmbientLightDocument. +layer.createObject(); + +expectTypeOf(layer.tearDown()).toEqualTypeOf>(); +expectTypeOf(layer.activate()).toEqualTypeOf(); +expectTypeOf(layer.deactivate()).toEqualTypeOf(); +expectTypeOf(layer.get("id")).toEqualTypeOf(); +expectTypeOf(layer.controlAll()).toEqualTypeOf(); +expectTypeOf(layer.controlAll({})).toEqualTypeOf(); +expectTypeOf(layer.controlAll({ releaseOthers: true })).toEqualTypeOf(); +expectTypeOf(layer.releaseAll()).toEqualTypeOf(); +expectTypeOf(layer.releaseAll({})).toEqualTypeOf(); +expectTypeOf(layer.releaseAll({ trigger: true })).toEqualTypeOf(); +expectTypeOf(layer.rotateMany()).toEqualTypeOf>(); +expectTypeOf(layer.rotateMany({})).toEqualTypeOf>(); +expectTypeOf(layer.rotateMany({ angle: 10, delta: 20, snap: 20, ids: ["abc", "def"] })).toEqualTypeOf< + Promise +>(); +expectTypeOf(layer.moveMany()).toEqualTypeOf | undefined>(); +expectTypeOf(layer.moveMany({})).toEqualTypeOf | undefined>(); +expectTypeOf(layer.moveMany({ dx: 100, dy: 100, rotate: true, ids: ["abc", "def"] })).toEqualTypeOf< + Promise | undefined +>(); +expectTypeOf(layer.undoHistory()).toEqualTypeOf>(); +expectTypeOf(layer.deleteAll()).toEqualTypeOf>(); +expectTypeOf(layer.storeHistory("create", new AmbientLightDocument().data)).toEqualTypeOf(); +expectTypeOf(layer.storeHistory("update", new AmbientLightDocument().data)).toEqualTypeOf(); +expectTypeOf(layer.storeHistory("delete", new AmbientLightDocument().data)).toEqualTypeOf(); + +// @ts-expect-error - "new" is not a valid history type. +layer.storeHistory("new", new AmbientLightDocument().data); + +expectTypeOf(layer.copyObjects()).toEqualTypeOf(); +expectTypeOf(layer.pasteObjects({ x: 10, y: 10 })).toEqualTypeOf>(); +expectTypeOf(layer.pasteObjects({ x: 10, y: 10 }, { hidden: true, snap: false })).toEqualTypeOf< + Promise +>(); +expectTypeOf(layer.pasteObjects({ x: 10, y: 10 }, { hidden: false })).toEqualTypeOf>(); +expectTypeOf(layer.pasteObjects({ x: 10, y: 10 }, { snap: true })).toEqualTypeOf>(); +expectTypeOf(layer.selectObjects()).toEqualTypeOf(); +expectTypeOf(layer.selectObjects({})).toEqualTypeOf(); +expectTypeOf( + layer.selectObjects({ + x: 10, + y: 10, + width: 100, + height: 200, + releaseOptions: { trigger: true }, + controlOptions: { releaseOthers: true }, + }), +).toEqualTypeOf(); + +declare function transformer(doc: AmbientLight): Partial; +declare function filter(doc: AmbientLight): boolean; +expectTypeOf(layer.updateAll({ x: 10, y: 20 })).toEqualTypeOf>(); +expectTypeOf(layer.updateAll({ x: 10, y: 20 }, null, {})).toEqualTypeOf>(); +expectTypeOf(layer.updateAll({ x: 10, y: 20 }, filter)).toEqualTypeOf>(); +expectTypeOf(layer.updateAll({ x: 10, y: 20 }, filter, { diff: false, noHook: false })).toEqualTypeOf< + Promise +>(); +expectTypeOf(layer.updateAll(transformer)).toEqualTypeOf>(); +expectTypeOf(layer.updateAll(transformer, null, {})).toEqualTypeOf>(); +expectTypeOf(layer.updateAll(transformer, filter)).toEqualTypeOf>(); +expectTypeOf(layer.updateAll(transformer, filter, { diff: true, noHook: true })).toEqualTypeOf< + Promise +>(); + +// @ts-expect-error - An x and y coordinate is required +layer.updateAll({ no_light_data: 0 }); diff --git a/tests/foundry/client/pixi/placeables/drawing.test-d.ts b/tests/foundry/client/pixi/placeables/drawing.test-d.ts new file mode 100644 index 000000000..b95b3aaf6 --- /dev/null +++ b/tests/foundry/client/pixi/placeables/drawing.test-d.ts @@ -0,0 +1,19 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(Drawing.embeddedName).toEqualTypeOf<"Drawing">(); + +const drawing = new Drawing(new DrawingDocument()); + +expectTypeOf(drawing.drawing).toEqualTypeOf(); +expectTypeOf(drawing.shape).toEqualTypeOf(); +expectTypeOf(drawing.text).toEqualTypeOf(); +expectTypeOf(drawing.frame).toEqualTypeOf(); + +expectTypeOf(drawing.isTiled).toEqualTypeOf(); +expectTypeOf(drawing.isPolygon).toEqualTypeOf(); + +expectTypeOf(drawing.draw()).toEqualTypeOf>(); + +expectTypeOf(drawing.refresh()).toEqualTypeOf(); + +expectTypeOf(drawing.activateListeners()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/placeables/light.test-d.ts b/tests/foundry/client/pixi/placeables/light.test-d.ts new file mode 100644 index 000000000..6a6c3e5eb --- /dev/null +++ b/tests/foundry/client/pixi/placeables/light.test-d.ts @@ -0,0 +1,19 @@ +import { expectTypeOf } from "vitest"; + +declare const doc: AmbientLightDocument; + +expectTypeOf(AmbientLight.embeddedName).toEqualTypeOf<"AmbientLight">(); + +const light = new AmbientLight(doc); +expectTypeOf(light.source).toEqualTypeOf(); +expectTypeOf(light.controlIcon).toEqualTypeOf(); +expectTypeOf(light.bounds).toEqualTypeOf(); +expectTypeOf(light.global).toEqualTypeOf(); +expectTypeOf(light.radius).toEqualTypeOf(); +expectTypeOf(light.dimRadius).toEqualTypeOf(); +expectTypeOf(light.brightRadius).toEqualTypeOf(); +expectTypeOf(light.isVisible).toEqualTypeOf(); +expectTypeOf(light.draw()).toEqualTypeOf>(); +expectTypeOf(light.refresh()).toEqualTypeOf(); +expectTypeOf(light.refreshControl()).toEqualTypeOf(); +expectTypeOf(light.sourceId).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/placeables/note.test-d.ts b/tests/foundry/client/pixi/placeables/note.test-d.ts new file mode 100644 index 000000000..c38b01526 --- /dev/null +++ b/tests/foundry/client/pixi/placeables/note.test-d.ts @@ -0,0 +1,11 @@ +import { expectTypeOf } from "vitest"; + +declare const doc: NoteDocument; + +expectTypeOf(Note.embeddedName).toEqualTypeOf<"Note">(); + +const note = new Note(doc); +expectTypeOf(note.entry).toEqualTypeOf(); +expectTypeOf(note.text).toEqualTypeOf(); +expectTypeOf(note.size).toEqualTypeOf(); +expectTypeOf(note.draw()).toEqualTypeOf>(); diff --git a/tests/foundry/client/pixi/placeables/sound.test-d.ts b/tests/foundry/client/pixi/placeables/sound.test-d.ts new file mode 100644 index 000000000..5ce263a52 --- /dev/null +++ b/tests/foundry/client/pixi/placeables/sound.test-d.ts @@ -0,0 +1,22 @@ +import { expectTypeOf } from "vitest"; + +declare const doc: AmbientSoundDocument; + +expectTypeOf(AmbientSound.embeddedName).toEqualTypeOf<"AmbientSound">(); + +// @ts-expect-error - An AmbientSound requires an AmbientSoundDocument. +new AmbientSound(); + +const sound = new AmbientSound(doc); +expectTypeOf(sound.sound).toEqualTypeOf(); +expectTypeOf(sound.isAudible).toEqualTypeOf(); +expectTypeOf(sound.radius).toEqualTypeOf(); +expectTypeOf(sound.sync(true, 10)).toEqualTypeOf(); +expectTypeOf(sound.sync(true, 10, {})).toEqualTypeOf(); +expectTypeOf(sound.sync(true, 10, { fade: 250 })).toEqualTypeOf(); +expectTypeOf(sound.clear()).toEqualTypeOf(); +expectTypeOf(sound.draw()).toEqualTypeOf>(); +expectTypeOf(sound.drawField()).toEqualTypeOf(); +expectTypeOf(sound.refresh()).toEqualTypeOf(); +expectTypeOf(sound.refreshControl()).toEqualTypeOf(); +expectTypeOf(sound.updateSource()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/placeables/template.test-d.ts b/tests/foundry/client/pixi/placeables/template.test-d.ts new file mode 100644 index 000000000..70b9b3f5c --- /dev/null +++ b/tests/foundry/client/pixi/placeables/template.test-d.ts @@ -0,0 +1,11 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(MeasuredTemplate.embeddedName).toEqualTypeOf<"MeasuredTemplate">(); + +const template = new MeasuredTemplate(new MeasuredTemplateDocument()); +expectTypeOf(template.draw()).toEqualTypeOf>(); +expectTypeOf(template.refresh()).toEqualTypeOf(); +expectTypeOf(template.data).toEqualTypeOf(); + +// TODO: Modify to the configured document sheet once the data can be grabbed from config +expectTypeOf(template.sheet).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/placeables/tile.test-d.ts b/tests/foundry/client/pixi/placeables/tile.test-d.ts new file mode 100644 index 000000000..8041e89c8 --- /dev/null +++ b/tests/foundry/client/pixi/placeables/tile.test-d.ts @@ -0,0 +1,36 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(Tile.embeddedName).toEqualTypeOf<"Tile">(); +expectTypeOf(Tile.createPreview({ x: 100, y: null })).toEqualTypeOf(); + +declare const doc: TileDocument; +const tile = new Tile(doc); +declare const token: Token; + +expectTypeOf(tile.frame).toEqualTypeOf(); +expectTypeOf(tile.texture).toEqualTypeOf(); +expectTypeOf(tile.tile).toEqualTypeOf(); +expectTypeOf(tile.bg).toEqualTypeOf(); +expectTypeOf(tile.occluded).toEqualTypeOf(); +expectTypeOf(tile.aspectRatio).toEqualTypeOf(); +expectTypeOf(tile.sourceElement).toEqualTypeOf(); +expectTypeOf(tile.isVideo).toEqualTypeOf(); +expectTypeOf(tile.isRoof).toEqualTypeOf(); +expectTypeOf(tile.draw()).toEqualTypeOf>(); +expectTypeOf(tile.refresh()).toEqualTypeOf(); + +expectTypeOf(tile.play(true)).toEqualTypeOf(); +expectTypeOf(tile.play(false, {})).toEqualTypeOf(); +expectTypeOf(tile.play(false, { loop: true, offset: 10, volume: 10 })).toEqualTypeOf(); + +expectTypeOf(tile.updateOcclusion([token])).toEqualTypeOf(); + +expectTypeOf(tile.testOcclusion(token)).toEqualTypeOf(); +expectTypeOf(tile.testOcclusion(token, {})).toEqualTypeOf(); +expectTypeOf(tile.testOcclusion(token, { corners: false })).toEqualTypeOf(); + +expectTypeOf(tile.containsPixel(236, 154)).toEqualTypeOf(); + +expectTypeOf(tile.getRoofSprite()).toEqualTypeOf(); +expectTypeOf(tile.swapLayer()).toEqualTypeOf(); +expectTypeOf(tile.activateListeners()).toEqualTypeOf(); diff --git a/tests/foundry/client/pixi/placeables/token.test-d.ts b/tests/foundry/client/pixi/placeables/token.test-d.ts new file mode 100644 index 000000000..c3c87c6a0 --- /dev/null +++ b/tests/foundry/client/pixi/placeables/token.test-d.ts @@ -0,0 +1,19 @@ +import type { ConfiguredDocumentClass } from "../../../../../src/types/helperTypes"; + +import { expectTypeOf } from "vitest"; + +const token = new Token(new TokenDocument()); +expectTypeOf(token.id).toEqualTypeOf(); +expectTypeOf(token.actor).toEqualTypeOf(); +expectTypeOf(token.data.actorId).toEqualTypeOf(); +expectTypeOf(token.data.actorLink).toEqualTypeOf(); +expectTypeOf(token.data.x).toEqualTypeOf(); +expectTypeOf(token.data.y).toEqualTypeOf(); +expectTypeOf(token.data.hidden).toEqualTypeOf(); +expectTypeOf(token.emitsLight).toEqualTypeOf(); +expectTypeOf(token.toggleVisibility()).toEqualTypeOf< + Promise>[]> +>(); +expectTypeOf(token.toggleEffect(CONFIG.statusEffects[0])).toEqualTypeOf>(); +expectTypeOf(token.toggleEffect(new ActiveEffect().data)).toEqualTypeOf>(); +expectTypeOf(token.toggleEffect("path/to/my/image.png")).toEqualTypeOf>(); diff --git a/tests/foundry/client/pixi/placeables/wall.test-d.ts b/tests/foundry/client/pixi/placeables/wall.test-d.ts new file mode 100644 index 000000000..2ed2548cc --- /dev/null +++ b/tests/foundry/client/pixi/placeables/wall.test-d.ts @@ -0,0 +1,25 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(Wall.embeddedName).toEqualTypeOf<"Wall">(); + +declare const doc: WallDocument; +declare const ray: Ray; + +const wall = new Wall(doc); +expectTypeOf(wall.doorControl).toEqualTypeOf(); +expectTypeOf(wall.mouseInteractionManager).toEqualTypeOf | null>(); +expectTypeOf(wall.roof).toEqualTypeOf(); +expectTypeOf(wall.coords).toEqualTypeOf<[number, number, number, number]>(); +expectTypeOf(wall.bounds).toEqualTypeOf(); +expectTypeOf(wall.midpoint).toEqualTypeOf<[number, number]>(); +expectTypeOf(wall.center).toEqualTypeOf(); +expectTypeOf(wall.direction).toEqualTypeOf(); +expectTypeOf(wall.toRay()).toEqualTypeOf(); +expectTypeOf(wall.draw()).toEqualTypeOf>(); +expectTypeOf(wall.isDirectionBetweenAngles(10, 20)).toEqualTypeOf(); +expectTypeOf(wall.canRayIntersect(ray)).toEqualTypeOf(); +expectTypeOf(wall.getLinkedSegments()).toEqualTypeOf<{ + ids: string[]; + walls: Wall[]; + endpoints: Array<[number, number]>; +}>(); diff --git a/test-d/foundry/client/pixi/webgl/base.test-d.ts b/tests/foundry/client/pixi/webgl/base.test-d.ts similarity index 60% rename from test-d/foundry/client/pixi/webgl/base.test-d.ts rename to tests/foundry/client/pixi/webgl/base.test-d.ts index 545d61416..a8d5920fe 100644 --- a/test-d/foundry/client/pixi/webgl/base.test-d.ts +++ b/tests/foundry/client/pixi/webgl/base.test-d.ts @@ -1,4 +1,4 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; class TestShader extends AbstractBaseShader { constructor(program: PIXI.Program, uniforms: AbstractBaseShader.Uniforms) { @@ -10,8 +10,8 @@ class TestShader extends AbstractBaseShader { } const testShader = TestShader.create(); -expectType(testShader.defaults.foo); -expectType(testShader.defaults.bar); +expectTypeOf(testShader.defaults.foo).toEqualTypeOf(); +expectTypeOf(testShader.defaults.bar).toEqualTypeOf(); const testShader2 = TestShader.create({ alpha: 1.0, @@ -23,4 +23,5 @@ const testShader2 = TestShader.create({ }); testShader2.defaults.darkness = false; -expectError(TestShader.create({ foo: "bar" })); +// @ts-expect-error - create requires a constructor for TestShader +TestShader.create({ foo: "bar" }); diff --git a/tests/foundry/client/pixi/webgl/filters.test-d.ts b/tests/foundry/client/pixi/webgl/filters.test-d.ts new file mode 100644 index 000000000..c813ca4c8 --- /dev/null +++ b/tests/foundry/client/pixi/webgl/filters.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; + +class CustomMaskFilter extends AbstractBaseMaskFilter {} + +expectTypeOf(CustomMaskFilter.create()).toEqualTypeOf(); + +expectTypeOf(InverseOcclusionMaskFilter.create()).toEqualTypeOf(); diff --git a/test-d/foundry/client/ui/context.test-d.ts b/tests/foundry/client/ui/context.test-d.ts similarity index 69% rename from test-d/foundry/client/ui/context.test-d.ts rename to tests/foundry/client/ui/context.test-d.ts index 57bc497c9..0d5e91d6b 100644 --- a/test-d/foundry/client/ui/context.test-d.ts +++ b/tests/foundry/client/ui/context.test-d.ts @@ -1,4 +1,4 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; declare const element: JQuery; new ContextMenu(element, undefined, []); @@ -17,6 +17,6 @@ const contextMenu = new ContextMenu(element, ".some-class", [ }, ]); -expectType(contextMenu.bind()); -expectType>(contextMenu.render(element)); -expectType(contextMenu.menuItems); +expectTypeOf(contextMenu.bind()).toEqualTypeOf(); +expectTypeOf(contextMenu.render(element)).toEqualTypeOf>(); +expectTypeOf(contextMenu.menuItems).toEqualTypeOf(); diff --git a/test-d/foundry/client/ui/dialog.test-d.ts b/tests/foundry/client/ui/dialog.test-d.ts similarity index 56% rename from test-d/foundry/client/ui/dialog.test-d.ts rename to tests/foundry/client/ui/dialog.test-d.ts index dfbcdfd1d..3d2b1daad 100644 --- a/test-d/foundry/client/ui/dialog.test-d.ts +++ b/tests/foundry/client/ui/dialog.test-d.ts @@ -1,4 +1,4 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; import "../../../index"; const title = "title"; @@ -6,575 +6,582 @@ const content = "content"; const label = "label"; const icon = ""; -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return true; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return false; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return true; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return false; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: { jQuery: false }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return true; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return false; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "bar"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, rejectClose: true, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, rejectClose: false, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return true; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return false; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "bar"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, rejectClose: true, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, rejectClose: false, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); const optionsWithJQueryUnknown = ((): Partial => ({}))(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return true; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return false; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, yes: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "foo"; }, no: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "bar"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, rejectClose: true, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, rejectClose: false, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.confirm({ title: title, content: content, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: { jQuery: true }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: { jQuery: false }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: {}, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return 0; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, render: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, options: optionsWithJQueryUnknown, }), -); +).toEqualTypeOf>(); // everything without "rejectClose" is tested above // now we need to test an explicitly given "rejectClose" -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, rejectClose: false, }), -); -expectType>( +).toEqualTypeOf>(); + +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, options: { jQuery: true }, rejectClose: false, }), -); -expectType>( +).toEqualTypeOf>(); + +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, options: { jQuery: false }, rejectClose: false, }), -); -expectType>( +).toEqualTypeOf>(); + +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, options: optionsWithJQueryUnknown, rejectClose: false, }), -); -expectType>( +).toEqualTypeOf>(); + +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, rejectClose: true, }), -); -expectType>( +).toEqualTypeOf>(); + +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, options: { jQuery: true }, rejectClose: true, }), -); -expectType>( +).toEqualTypeOf>(); + +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, options: { jQuery: false }, rejectClose: true, }), -); -expectType>( +).toEqualTypeOf>(); + +expectTypeOf( Dialog.prompt({ title: title, content: content, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); return "string"; }, options: optionsWithJQueryUnknown, rejectClose: true, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.prompt({ title: title, content: content, @@ -584,8 +591,8 @@ expectType>( }, rejectClose: true, }), -); -expectType>( +).toEqualTypeOf>(); +expectTypeOf( Dialog.prompt({ title: title, content: content, @@ -595,8 +602,8 @@ expectType>( }, rejectClose: false, }), -); -expectType>( +).toEqualTypeOf>(); +expectTypeOf( Dialog.prompt({ title: title, content: content, @@ -606,8 +613,8 @@ expectType>( }, rejectClose: true, }), -); -expectType>( +).toEqualTypeOf>(); +expectTypeOf( Dialog.prompt({ title: title, content: content, @@ -617,8 +624,8 @@ expectType>( }, rejectClose: false, }), -); -expectType>( +).toEqualTypeOf>(); +expectTypeOf( Dialog.prompt({ title: title, content: content, @@ -628,9 +635,9 @@ expectType>( }, rejectClose: true, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.wait({ title: title, content: content, @@ -639,14 +646,14 @@ expectType>( icon: icon, label: label, callback: (jqOrHtml: JQuery | HTMLElement) => { - expectType(jqOrHtml); + expectTypeOf(jqOrHtml).toEqualTypeOf(); }, }, }, }), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.wait( { title: title, @@ -656,7 +663,7 @@ expectType>( icon: icon, label: label, callback: (jq) => { - expectType(jq); + expectTypeOf(jq).toEqualTypeOf(); }, }, }, @@ -665,9 +672,9 @@ expectType>( jQuery: true, }, ), -); +).toEqualTypeOf>(); -expectType>( +expectTypeOf( Dialog.wait( { title: title, @@ -677,7 +684,7 @@ expectType>( icon: icon, label: label, callback: (html) => { - expectType(html); + expectTypeOf(html).toEqualTypeOf(); }, }, }, @@ -686,4 +693,4 @@ expectType>( jQuery: false, }, ), -); +).toEqualTypeOf>(); diff --git a/tests/foundry/client/ui/drag.test-d.ts b/tests/foundry/client/ui/drag.test-d.ts new file mode 100644 index 000000000..6b21cce7d --- /dev/null +++ b/tests/foundry/client/ui/drag.test-d.ts @@ -0,0 +1,19 @@ +import { expectTypeOf } from "vitest"; +import "../../index"; + +const App = class extends Application {}; +const resizableUndefined = new Draggable(new App(), $(), new HTMLElement()); +expectTypeOf(resizableUndefined.resizable).toEqualTypeOf(); +expectTypeOf(resizableUndefined.handlers).toEqualTypeOf(); + +const maybeResizable = new Draggable(new App(), $(), new HTMLElement(), ((): boolean => false)()); +expectTypeOf(maybeResizable.resizable).toEqualTypeOf(); +expectTypeOf(maybeResizable.handlers).toEqualTypeOf(); + +const nonResizable = new Draggable(new App(), $(), new HTMLElement(), false); +expectTypeOf(nonResizable.resizable).toEqualTypeOf(); +expectTypeOf(nonResizable.handlers).toEqualTypeOf(); + +const resizable = new Draggable(new App(), $(), new HTMLElement(), true); +expectTypeOf(resizable.resizable).toEqualTypeOf(); +expectTypeOf(resizable.handlers).toEqualTypeOf(); diff --git a/tests/foundry/client/ui/filter.test-d.ts b/tests/foundry/client/ui/filter.test-d.ts new file mode 100644 index 000000000..924b1d088 --- /dev/null +++ b/tests/foundry/client/ui/filter.test-d.ts @@ -0,0 +1,37 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - A SearchFilter requires data. +new SearchFilter(); + +// @ts-expect-error - A SearchFilter requires an `inputSelector` and a `contentSelector`. +new SearchFilter({}); + +expectTypeOf( + new SearchFilter({ + inputSelector: "input", + contentSelector: ".my-class", + callback: (event: KeyboardEvent, query: string, rgx: RegExp, content: string): void => { + rgx.exec(content); + }, + }), +).toEqualTypeOf(); + +const filter = new SearchFilter({ + inputSelector: "input", + contentSelector: ".my-class", + callback: (event: KeyboardEvent, query: string, rgx: RegExp, content: string): void => { + rgx.exec(content); + }, + initial: "Type here", + delay: 100, +}); + +expectTypeOf(filter.query).toEqualTypeOf(); +expectTypeOf(filter.callback).toEqualTypeOf< + (event: KeyboardEvent, query: string, rgx: RegExp, content: string) => void +>(); +expectTypeOf(filter.rgx).toEqualTypeOf(); +expectTypeOf(filter.bind(new HTMLDivElement())).toEqualTypeOf(); +expectTypeOf(filter.filter(new KeyboardEvent("keyup"), "Typed")).toEqualTypeOf(); + +expectTypeOf(SearchFilter.cleanQuery(" my-query")).toEqualTypeOf(); diff --git a/tests/foundry/client/ui/notifications.test-d.ts b/tests/foundry/client/ui/notifications.test-d.ts new file mode 100644 index 000000000..7b7bafe75 --- /dev/null +++ b/tests/foundry/client/ui/notifications.test-d.ts @@ -0,0 +1,40 @@ +import { expectTypeOf } from "vitest"; + +const notifications = new Notifications(); +expectTypeOf(notifications.queue).toEqualTypeOf< + Array<{ + message: string; + type: "info" | "warning" | "error"; + timestamp: number; + console: boolean; + permanent: boolean; + }> +>(); +expectTypeOf(notifications.active).toEqualTypeOf(); + +expectTypeOf(notifications.notify("Hello world")).toEqualTypeOf(); +expectTypeOf(notifications.notify("Hello world", "info")).toEqualTypeOf(); +expectTypeOf(notifications.notify("Hello world", "warning")).toEqualTypeOf(); +expectTypeOf(notifications.notify("Hello world", "error")).toEqualTypeOf(); + +// @ts-expect-error - "success" is not a valid notification type. +notifications.notify("Hello world", "success"); + +expectTypeOf(notifications.notify("Hello world", "error", { localize: true })).toEqualTypeOf(); +expectTypeOf(notifications.notify("Hello world", "error", { permanent: true })).toEqualTypeOf(); +expectTypeOf(notifications.notify("Hello world", "error", { console: false })).toEqualTypeOf(); + +expectTypeOf(notifications.info("Hello world")).toEqualTypeOf(); +expectTypeOf(notifications.info("Hello world", { localize: true })).toEqualTypeOf(); +expectTypeOf(notifications.info("Hello world", { permanent: true })).toEqualTypeOf(); +expectTypeOf(notifications.info("Hello world", { console: false })).toEqualTypeOf(); + +expectTypeOf(notifications.warn("Hello world")).toEqualTypeOf(); +expectTypeOf(notifications.warn("Hello world", { localize: true })).toEqualTypeOf(); +expectTypeOf(notifications.warn("Hello world", { permanent: true })).toEqualTypeOf(); +expectTypeOf(notifications.warn("Hello world", { console: false })).toEqualTypeOf(); + +expectTypeOf(notifications.error("Hello world")).toEqualTypeOf(); +expectTypeOf(notifications.error("Hello world", { localize: true })).toEqualTypeOf(); +expectTypeOf(notifications.error("Hello world", { permanent: true })).toEqualTypeOf(); +expectTypeOf(notifications.error("Hello world", { console: false })).toEqualTypeOf(); diff --git a/tests/foundry/client/ui/prosemirror.test-d.ts b/tests/foundry/client/ui/prosemirror.test-d.ts new file mode 100644 index 000000000..fde1a7649 --- /dev/null +++ b/tests/foundry/client/ui/prosemirror.test-d.ts @@ -0,0 +1,18 @@ +import { assertType } from "vitest"; + +assertType(ProseMirrorEditor); +type ProseMirrorEditorCreateFuncOptions = Parameters<(typeof ProseMirrorEditor)["create"]>[2]; +declare const document: Actor; + +// @ts-expect-error - both `document` and `fieldName` are required. +expectTypeOf({ collaborate: true }).toEqualTypeOf(); + +// @ts-expect-error - both `document` and `fieldName` are required. +expectTypeOf({ collaborate: true, document }).toEqualTypeOf(); + +// @ts-expect-error - both `document` and `fieldName` are required. +expectTypeOf({ collaborate: true, fieldName: "error" }).toEqualTypeOf(); + +assertType({ collaborate: true, document: document, fieldName: "valid" }); +assertType({}); +assertType({ collaborate: false }); diff --git a/tests/foundry/client/ui/tabs.test-d.ts b/tests/foundry/client/ui/tabs.test-d.ts new file mode 100644 index 000000000..c6c836d4a --- /dev/null +++ b/tests/foundry/client/ui/tabs.test-d.ts @@ -0,0 +1,29 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - Tabs requires data. +new Tabs(); + +// @ts-expect-error - Tabs requires a navSelector. +new Tabs({}); + +expectTypeOf(new Tabs({ navSelector: ".tabs" })).toEqualTypeOf(); +const tabs = new Tabs({ + navSelector: ".tabs", + contentSelector: ".content", + initial: "tab1", + callback: (event: MouseEvent | null, tabs: Tabs, active: string): void => { + console.log(active); + }, +}); + +expectTypeOf(tabs.active).toEqualTypeOf(); +expectTypeOf(tabs.callback).toEqualTypeOf< + ((event: MouseEvent | null, tabs: Tabs, tabName: string) => unknown) | null | undefined +>(); + +tabs.bind(new HTMLDivElement()); +tabs.activate("tab1"); +tabs.activate("tab1", {}); +tabs.activate("tab1", { triggerCallback: true }); + +expectTypeOf(TabsV2).toEqualTypeOf(); diff --git a/tests/foundry/common/abstract/data.mjs.test-d.ts b/tests/foundry/common/abstract/data.mjs.test-d.ts new file mode 100644 index 000000000..65e681bb5 --- /dev/null +++ b/tests/foundry/common/abstract/data.mjs.test-d.ts @@ -0,0 +1,19 @@ +import type { + EffectChangeData, + EffectChangeDataProperties, +} from "../../../../src/foundry/common/data/data.mjs/effectChangeData"; + +import { expectTypeOf } from "vitest"; +import "../../../../index"; + +// @ts-expect-error - ActorData requires data. +new foundry.data.ActorData(); + +// @ts-expect-error - ActorData requires a `name` and `type`. +new foundry.data.ActorData({}); + +const activeEffectData = new foundry.data.ActiveEffectData(); +expectTypeOf(activeEffectData.toJSON().changes).toEqualTypeOf(); +expectTypeOf(activeEffectData.toObject().changes).toEqualTypeOf(); +expectTypeOf(activeEffectData.toObject(true).changes).toEqualTypeOf(); +expectTypeOf(activeEffectData.toObject(false).changes).toEqualTypeOf(); diff --git a/tests/foundry/common/abstract/document.mjs.test-d.ts b/tests/foundry/common/abstract/document.mjs.test-d.ts new file mode 100644 index 000000000..25ea5150f --- /dev/null +++ b/tests/foundry/common/abstract/document.mjs.test-d.ts @@ -0,0 +1,133 @@ +import type { ActiveEffectDataSource } from "../../../../src/foundry/common/data/data.mjs/activeEffectData"; +import type { + EffectChangeData, + EffectChangeDataProperties, +} from "../../../../src/foundry/common/data/data.mjs/effectChangeData"; +import { expectTypeOf } from "vitest"; + +const baseActiveEffect = new foundry.documents.BaseActiveEffect(); + +expectTypeOf(baseActiveEffect.toJSON().changes).toEqualTypeOf(); +expectTypeOf(baseActiveEffect.toObject().changes).toEqualTypeOf(); +expectTypeOf(baseActiveEffect.toObject(true).changes).toEqualTypeOf(); +expectTypeOf(baseActiveEffect.toObject(false).changes).toEqualTypeOf(); + +const item = await Item.create({ name: "Some Item", type: "weapon" }); +if (item) { + expectTypeOf(item.toObject(false).effects[0].changes).toEqualTypeOf(); + expectTypeOf(item.toObject().effects).toEqualTypeOf(); +} + +declare const bool: boolean; + +expectTypeOf(foundry.documents.BaseMacro.create({ name: "" }, { temporary: bool })).toEqualTypeOf< + Promise +>(); +expectTypeOf(foundry.documents.BaseMacro.create({ name: "" }, { temporary: true })).toEqualTypeOf< + Promise +>(); +expectTypeOf(foundry.documents.BaseMacro.create({ name: "" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseMacro.create({ name: "" }, { temporary: false })).toEqualTypeOf< + Promise | undefined> +>(); + +expectTypeOf(foundry.documents.BaseMacro.createDocuments([], { temporary: bool })).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseMacro.createDocuments([], { temporary: true })).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseMacro.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(foundry.documents.BaseMacro.createDocuments([], { temporary: false })).toEqualTypeOf< + Promise[]> +>(); + +expectTypeOf(foundry.documents.BaseMacro.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseMacro.deleteDocuments([])).toEqualTypeOf>(); +const user = await User.create({ name: "Some User" }); +if (user) { + expectTypeOf(user.testUserPermission(user, "NONE")).toEqualTypeOf(); + expectTypeOf(user.testUserPermission(user, "OBSERVER", {})).toEqualTypeOf(); + expectTypeOf(user.testUserPermission(user, "LIMITED", { exact: true })).toEqualTypeOf(); + expectTypeOf(user.testUserPermission(user, "OWNER", { exact: false })).toEqualTypeOf(); +} + +// test creation of embedded documents +declare const actor: Actor; +expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: true })).toEqualTypeOf< + Promise[]> +>(); +expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: bool })).toEqualTypeOf< + Promise[]> +>(); +expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [], { temporary: false })).toEqualTypeOf< + Promise>[]> +>(); +expectTypeOf(actor.createEmbeddedDocuments("ActiveEffect", [])).toEqualTypeOf< + Promise>[]> +>(); + +// verify that document lifecycle methods work with source data is possible + +if (item) { + expectTypeOf(Item.createDocuments([item.toObject()])).toEqualTypeOf[]>>(); + expectTypeOf(Item.create(item.toObject())).toEqualTypeOf | undefined>>(); + expectTypeOf(Item.updateDocuments([item.toObject()])).toEqualTypeOf>(); + expectTypeOf(item.update(item.toObject())).toEqualTypeOf | undefined>>(); + expectTypeOf(item.clone(item.toObject())).toEqualTypeOf>(); +} + +declare global { + interface FlagConfig { + Combatant: { + "my-system": { + value: boolean; + value2: number; + }; + "my-optional-system"?: { + value: boolean; + }; + }; + } +} + +const combatant = new Combatant({}, {}); +expectTypeOf(combatant.data.flags["my-system"]).toEqualTypeOf<{ value: boolean; value2: number }>(); +expectTypeOf(combatant.data.flags["my-optional-system"]).toEqualTypeOf<{ value: boolean } | undefined>(); + +expectTypeOf(combatant.getFlag("my-system", "value")).toEqualTypeOf(); +expectTypeOf(combatant.getFlag("my-system", "value2")).toEqualTypeOf(); +expectTypeOf(combatant.getFlag("my-system", "unknown-key")).toEqualTypeOf(); +expectTypeOf(combatant.getFlag("another-system", "value")).toEqualTypeOf(); +expectTypeOf(combatant.getFlag("my-optional-system", "value")).toEqualTypeOf(); + +expectTypeOf(combatant.setFlag("my-system", "value", true)).toEqualTypeOf>(); + +// @ts-expect-error - the flag my-system.value is a boolean and not a number +combatant.setFlag("my-system", "value", 2); + +// @ts-expect-error - the flag my-system.unknown-key doesn't exist +combatant.setFlag("my-system", "unknown-key", 2); + +expectTypeOf(combatant.setFlag("my-optional-system", "value", true)).toEqualTypeOf>(); + +// @ts-expect-error - an optional system with a required flag can't be assigned an undefined value +combatant.setFlag("my-optional-system", "value", undefined); + +expectTypeOf(combatant.setFlag("another-system", "value", true)).toEqualTypeOf>(); + +expectTypeOf(combatant.unsetFlag("my-system", "value")).toEqualTypeOf>(); +expectTypeOf(combatant.unsetFlag("my-optional-system", "value")).toEqualTypeOf>(); +expectTypeOf(combatant.unsetFlag("another-system", "value")).toEqualTypeOf>(); + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +class MyCombatant extends Combatant { + setSomeFlag() { + expectTypeOf(this.data.flags["my-system"]).toEqualTypeOf<{ value: boolean; value2: number }>(); + expectTypeOf(this.data.flags["my-optional-system"]).toEqualTypeOf<{ value: boolean } | undefined>(); + + expectTypeOf(this.getFlag("my-system", "value")).toEqualTypeOf(); + expectTypeOf(this.getFlag("another-system", "value")).toEqualTypeOf(); + + expectTypeOf(this.setFlag("my-system", "value", true)).toEqualTypeOf>(); + expectTypeOf(this.setFlag("another-system", "value", true)).toEqualTypeOf>(); + } +} diff --git a/tests/foundry/common/data/data.mjs/actorData.test-d.ts b/tests/foundry/common/data/data.mjs/actorData.test-d.ts new file mode 100644 index 000000000..877e727c2 --- /dev/null +++ b/tests/foundry/common/data/data.mjs/actorData.test-d.ts @@ -0,0 +1,112 @@ +import { expectTypeOf } from "vitest"; +import "../../../../../index"; + +interface CharacterDataSourceData { + health: number; +} + +interface CharacterFlags { + "my-module": { + known: boolean; + xp: number; + }; +} + +interface CharacterDataSource { + type: "character"; + data: CharacterDataSourceData; + flags: CharacterFlags; +} + +interface CharacterDataPropertiesData extends CharacterDataSourceData { + movement: number; +} + +interface CharacterDataProperties { + type: "character"; + data: CharacterDataPropertiesData; + flags: CharacterFlags; +} + +interface NPCDataSourceData { + challenge: number; + faction: string; +} + +interface NPCFlags { + "my-module": { + "hidden-name": string; + known: boolean; + }; +} + +interface NPCDataSource { + type: "npc"; + data: NPCDataSourceData; + flags: NPCFlags; +} + +interface NPCDataPropertiesData extends NPCDataSourceData { + damage: number; +} + +interface NPCDataProperties { + type: "npc"; + data: NPCDataPropertiesData; + flags: NPCFlags; +} + +type MyActorDataSource = CharacterDataSource | NPCDataSource; +type MyActorDataProperties = CharacterDataProperties | NPCDataProperties; + +declare global { + interface DataConfig { + Actor: MyActorDataProperties; + } + + interface SourceConfig { + Actor: MyActorDataSource; + } +} + +// @ts-expect-error - An ActorData requires data. +new foundry.data.ActorData(); + +// @ts-expect-error - An ActorData requires a name and type. +new foundry.data.ActorData({}); + +// @ts-expect-error - The type "foo" has not been configured as a valid actor type. +new foundry.data.ActorData({ name: "Some Actor With Wrong Type", type: "foo" }); + +const actorData = new foundry.data.ActorData({ name: "Some Actor", type: "character" }); + +expectTypeOf(actorData).toEqualTypeOf(); +expectTypeOf(actorData.type).toEqualTypeOf<"character" | "npc">(); + +if (actorData._source.type === "character") { + expectTypeOf(actorData._source.data.health).toEqualTypeOf(); + + // @ts-expect-error - The property "movement" does not exist on the character _source. + actorData._source.data.movement; + + expectTypeOf(actorData._source.flags["my-module"].xp).toEqualTypeOf(); +} else { + expectTypeOf(actorData._source.data.faction).toEqualTypeOf(); + expectTypeOf(actorData._source.data.challenge).toEqualTypeOf(); + + // @ts-expect-error - The property "damage" does not exist on the npc _source. + actorData._source.data.damage; + + expectTypeOf(actorData._source.flags["my-module"]["hidden-name"]).toEqualTypeOf(); +} + +if (actorData.type === "character") { + expectTypeOf(actorData.data.health).toEqualTypeOf(); + expectTypeOf(actorData.data.movement).toEqualTypeOf(); + expectTypeOf(actorData.flags["my-module"].xp).toEqualTypeOf(); +} else { + expectTypeOf(actorData.data.faction).toEqualTypeOf(); + expectTypeOf(actorData.data.challenge).toEqualTypeOf(); + expectTypeOf(actorData.data.damage).toEqualTypeOf(); + expectTypeOf(actorData.flags["my-module"]["hidden-name"]).toEqualTypeOf(); +} diff --git a/test-d/foundry/common/data/data.mjs/ambientSoundData.test-d.ts b/tests/foundry/common/data/data.mjs/ambientSoundData.test-d.ts similarity index 62% rename from test-d/foundry/common/data/data.mjs/ambientSoundData.test-d.ts rename to tests/foundry/common/data/data.mjs/ambientSoundData.test-d.ts index 757b77f48..258a7e6bb 100644 --- a/test-d/foundry/common/data/data.mjs/ambientSoundData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/ambientSoundData.test-d.ts @@ -1,8 +1,8 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; -expectType(new foundry.data.AmbientSoundData()); -expectType(new foundry.data.AmbientSoundData({})); -expectType( +expectTypeOf(new foundry.data.AmbientSoundData()).toEqualTypeOf(); +expectTypeOf(new foundry.data.AmbientSoundData({})).toEqualTypeOf(); +expectTypeOf( new foundry.data.AmbientSoundData({ _id: null, x: 10, @@ -15,8 +15,8 @@ expectType( repeat: true, volume: 100, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.AmbientSoundData({ _id: null, x: null, @@ -29,8 +29,8 @@ expectType( repeat: null, volume: null, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.AmbientSoundData({ _id: undefined, x: undefined, @@ -43,4 +43,4 @@ expectType( repeat: undefined, volume: undefined, }), -); +).toEqualTypeOf(); diff --git a/test-d/foundry/common/data/data.mjs/cardData.test-d.ts b/tests/foundry/common/data/data.mjs/cardData.test-d.ts similarity index 53% rename from test-d/foundry/common/data/data.mjs/cardData.test-d.ts rename to tests/foundry/common/data/data.mjs/cardData.test-d.ts index a63361373..9eda6a414 100644 --- a/test-d/foundry/common/data/data.mjs/cardData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/cardData.test-d.ts @@ -1,4 +1,4 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; interface OldCardDataSourceData { condition: "grubby"; @@ -67,28 +67,37 @@ declare global { } } -expectError(new foundry.data.CardData()); -expectError(new foundry.data.CardData({})); -expectType(new foundry.data.CardData({ name: "Some Card" })); +// @ts-expect-error - CardData requires data. +new foundry.data.CardData(); -expectError(new foundry.data.CardData({ name: "Some Card With Wrong Type", type: "foo" })); +// @ts-expect-error - CardData requires a name. +new foundry.data.CardData({}); + +expectTypeOf(new foundry.data.CardData({ name: "Some Card" })).toEqualTypeOf(); + +// @ts-expect-error - "foo" is not a type that's been configured for Cards. +new foundry.data.CardData({ name: "Some Card With Wrong Type", type: "foo" }); const cardData = new foundry.data.CardData({ name: "Some Card", face: 42, type: "old" }); -expectType(cardData); -expectType<"old" | "uno">(cardData.type); +expectTypeOf(cardData).toEqualTypeOf(); +expectTypeOf(cardData.type).toEqualTypeOf<"old" | "uno">(); if (cardData._source.type === "old") { - expectType<"grubby">(cardData._source.data.condition); - expectError(cardData._source.data.age); + expectTypeOf(cardData._source.data.condition).toEqualTypeOf<"grubby">(); + + // @ts-expect-error - age doesn't exist on OldCardDataSourceData + cardData._source.data.age; } else { - expectType(cardData._source.data.special); - expectError(cardData._source.data.color); + expectTypeOf(cardData._source.data.special).toEqualTypeOf(); + + // @ts-expect-error - color doesn't exist on UnoCardDataSourceData + cardData._source.data.color; } if (cardData.type === "old") { - expectType<"grubby">(cardData.data.condition); - expectType(cardData.data.age); + expectTypeOf(cardData.data.condition).toEqualTypeOf<"grubby">(); + expectTypeOf(cardData.data.age).toEqualTypeOf(); } else { - expectType(cardData.data.special); - expectType(cardData.data.color); + expectTypeOf(cardData.data.special).toEqualTypeOf(); + expectTypeOf(cardData.data.color).toEqualTypeOf(); } diff --git a/tests/foundry/common/data/data.mjs/cardsData.test-d.ts b/tests/foundry/common/data/data.mjs/cardsData.test-d.ts new file mode 100644 index 000000000..172078e20 --- /dev/null +++ b/tests/foundry/common/data/data.mjs/cardsData.test-d.ts @@ -0,0 +1,85 @@ +import { expectTypeOf } from "vitest"; + +interface GermanDeckDataSourceData { + mostUsedGame: "Skat"; +} + +interface GermanDeckDataSource { + type: "german"; + data: GermanDeckDataSourceData; +} + +interface FrenchDeckDataSourceData { + coolUse: "throwing cards"; +} + +interface FrenchDeckDataSource { + type: "french"; + data: FrenchDeckDataSourceData; +} + +interface GermanDeckDataPropertiesData extends GermanDeckDataSourceData { + mostUsedBy: "older players"; +} + +interface GermanDeckDataProperties { + type: "german"; + data: GermanDeckDataPropertiesData; +} + +interface FrenchDeckDataPropertiesData extends FrenchDeckDataSourceData { + possibleInjuries: "card stuck in eye"; +} + +interface FrenchDeckDataProperties { + type: "french"; + data: FrenchDeckDataPropertiesData; +} + +type MyCardsDataSource = GermanDeckDataSource | FrenchDeckDataSource; +type MyCardsDataProperties = GermanDeckDataProperties | FrenchDeckDataProperties; + +declare global { + interface DataConfig { + Cards: MyCardsDataProperties; + } + + interface SourceConfig { + Cards: MyCardsDataSource; + } +} + +// @ts-expect-error - CardsData requires data. +new foundry.data.CardsData(); + +// @ts-expect-error - CardsData requires a name. +new foundry.data.CardsData({}); + +expectTypeOf(new foundry.data.CardsData({ name: "Some Cards" })).toEqualTypeOf(); + +// @ts-expect-error - "foo" is not a configured type for a Card. +new foundry.data.CardsData({ name: "Some Cards With Wrong Type", type: "foo" }); + +const cardsData = new foundry.data.CardsData({ name: "Some Deck", type: "french" }); + +expectTypeOf(cardsData).toEqualTypeOf(); +expectTypeOf(cardsData.type).toEqualTypeOf<"french" | "german">(); +if (cardsData._source.type === "french") { + expectTypeOf(cardsData._source.data.coolUse).toEqualTypeOf<"throwing cards">(); + + // @ts-expect-error - possibleInjuries doesn't exist on FrenchDeckDataSourceData. + cardsData._source.data.possibleInjuries; +} else { + expectTypeOf(cardsData._source.data.mostUsedGame).toEqualTypeOf<"Skat">(); + + // @ts-expect-error - possibleInjuries doesn't exist on GermanDeckDataSourceData. + cardsData._source.data.mostUsedBy; +} + +if (cardsData.type === "french") { + expectTypeOf(cardsData.data.coolUse).toEqualTypeOf<"throwing cards">(); + expectTypeOf(cardsData.data.possibleInjuries).toEqualTypeOf<"card stuck in eye">(); +} else { + expectTypeOf(cardsData.data.mostUsedGame).toEqualTypeOf<"Skat">(); + expectTypeOf(cardsData.data.mostUsedBy).toEqualTypeOf<"older players">(); +} diff --git a/test-d/foundry/common/data/data.mjs/chatMessageData.test-d.ts b/tests/foundry/common/data/data.mjs/chatMessageData.test-d.ts similarity index 61% rename from test-d/foundry/common/data/data.mjs/chatMessageData.test-d.ts rename to tests/foundry/common/data/data.mjs/chatMessageData.test-d.ts index fa0f6965e..e2fb48368 100644 --- a/test-d/foundry/common/data/data.mjs/chatMessageData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/chatMessageData.test-d.ts @@ -1,8 +1,8 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; -expectType(new foundry.data.ChatMessageData()); -expectType(new foundry.data.ChatMessageData({})); -expectType( +expectTypeOf(new foundry.data.ChatMessageData()).toEqualTypeOf(); +expectTypeOf(new foundry.data.ChatMessageData({})).toEqualTypeOf(); +expectTypeOf( new foundry.data.ChatMessageData({ blind: null, content: null, @@ -18,8 +18,8 @@ expectType( whisper: null, _id: null, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.ChatMessageData({ blind: undefined, content: undefined, @@ -35,9 +35,9 @@ expectType( whisper: undefined, _id: undefined, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.ChatMessageData({ speaker: { scene: null, @@ -46,13 +46,13 @@ expectType( alias: null, }, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.ChatMessageData({ speaker: {}, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.ChatMessageData({ speaker: { scene: undefined, @@ -61,20 +61,20 @@ expectType( alias: undefined, }, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.ChatMessageData({ whisper: null, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.ChatMessageData({ whisper: ["someId"], }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.ChatMessageData({ whisper: [{ id: "someId" }], }), -); +).toEqualTypeOf(); diff --git a/tests/foundry/common/data/data.mjs/combatData.test-d.ts b/tests/foundry/common/data/data.mjs/combatData.test-d.ts new file mode 100644 index 000000000..2b04e77a1 --- /dev/null +++ b/tests/foundry/common/data/data.mjs/combatData.test-d.ts @@ -0,0 +1,5 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(new foundry.data.CombatData()).toEqualTypeOf(); +expectTypeOf(new foundry.data.CombatData({})).toEqualTypeOf(); +expectTypeOf(new foundry.data.CombatData({ scene: "foo", active: true })).toEqualTypeOf(); diff --git a/tests/foundry/common/data/data.mjs/combatantData.test-d.ts b/tests/foundry/common/data/data.mjs/combatantData.test-d.ts new file mode 100644 index 000000000..6f06c1aa6 --- /dev/null +++ b/tests/foundry/common/data/data.mjs/combatantData.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(new foundry.data.CombatantData()).toEqualTypeOf(); +expectTypeOf(new foundry.data.CombatantData({})).toEqualTypeOf(); +expectTypeOf( + new foundry.data.CombatantData({ tokenId: "foo", actorId: "bar" }), +).toEqualTypeOf(); diff --git a/test-d/foundry/common/data/data.mjs/drawingData.test-d.ts b/tests/foundry/common/data/data.mjs/drawingData.test-d.ts similarity index 80% rename from test-d/foundry/common/data/data.mjs/drawingData.test-d.ts rename to tests/foundry/common/data/data.mjs/drawingData.test-d.ts index ec9141c37..a18ed2a35 100644 --- a/test-d/foundry/common/data/data.mjs/drawingData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/drawingData.test-d.ts @@ -1,8 +1,8 @@ -import { expectType } from "tsd"; +import { expectTypeOf } from "vitest"; -expectType(new foundry.data.DrawingData()); -expectType(new foundry.data.DrawingData({})); -expectType( +expectTypeOf(new foundry.data.DrawingData()).toEqualTypeOf(); +expectTypeOf(new foundry.data.DrawingData({})).toEqualTypeOf(); +expectTypeOf( new foundry.data.DrawingData({ author: null, bezierFactor: null, @@ -30,8 +30,8 @@ expectType( z: null, _id: null, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.DrawingData({ author: undefined, bezierFactor: undefined, @@ -59,9 +59,9 @@ expectType( z: undefined, _id: undefined, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.DrawingData({ author: new User(), bezierFactor: 0, @@ -89,4 +89,4 @@ expectType( z: 0, _id: "NlBhrPq62QrMErNh", }), -); +).toEqualTypeOf(); diff --git a/test-d/foundry/common/data/data.mjs/fogExplorationData.test-d.ts b/tests/foundry/common/data/data.mjs/fogExplorationData.test-d.ts similarity index 60% rename from test-d/foundry/common/data/data.mjs/fogExplorationData.test-d.ts rename to tests/foundry/common/data/data.mjs/fogExplorationData.test-d.ts index 9da5f56d0..afbc798c8 100644 --- a/test-d/foundry/common/data/data.mjs/fogExplorationData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/fogExplorationData.test-d.ts @@ -1,4 +1,4 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; declare const scene: Scene; declare const user: User; @@ -16,7 +16,10 @@ new foundry.data.FogExplorationData({ new foundry.data.FogExplorationData({ scene: scene, }); -expectError(foundry.data.FogExplorationData({ user: user })); + +// @ts-expect-error - `new` must be used. +foundry.data.FogExplorationData({ user: user }); + new foundry.data.FogExplorationData({ explored: null, positions: null, @@ -36,9 +39,9 @@ new foundry.data.FogExplorationData({ new foundry.data.FogExplorationData({}); const data = new foundry.data.FogExplorationData(); -expectType(data.explored); -expectType>(data.positions); -expectType(data.scene); -expectType(data.timestamp); -expectType(data.user); -expectType(data._id); +expectTypeOf(data.explored).toEqualTypeOf(); +expectTypeOf(data.positions).toEqualTypeOf>(); +expectTypeOf(data.scene).toEqualTypeOf(); +expectTypeOf(data.timestamp).toEqualTypeOf(); +expectTypeOf(data.user).toEqualTypeOf(); +expectTypeOf(data._id).toEqualTypeOf(); diff --git a/tests/foundry/common/data/data.mjs/folderData.test-d.ts b/tests/foundry/common/data/data.mjs/folderData.test-d.ts new file mode 100644 index 000000000..e92521f1e --- /dev/null +++ b/tests/foundry/common/data/data.mjs/folderData.test-d.ts @@ -0,0 +1,14 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - FolderData requires data. +new foundry.data.FolderData(); + +// @ts-expect-error - FolderData requires a name and type. +new foundry.data.FolderData({}); + +// @ts-expect-error - foo is not a configured type for a Folder. +new foundry.data.FolderData({ name: "foo", type: "foo" }); + +expectTypeOf( + new foundry.data.FolderData({ name: "foo", type: foundry.CONST.FOLDER_DOCUMENT_TYPES[0] }), +).toEqualTypeOf(); diff --git a/tests/foundry/common/data/data.mjs/itemData.test-d.ts b/tests/foundry/common/data/data.mjs/itemData.test-d.ts new file mode 100644 index 000000000..b108495b6 --- /dev/null +++ b/tests/foundry/common/data/data.mjs/itemData.test-d.ts @@ -0,0 +1,87 @@ +import { expectTypeOf } from "vitest"; +import "../../../../../index"; + +interface ArmorDataSourceData { + armorValue: number; +} + +interface ArmorDataSource { + type: "armor"; + data: ArmorDataSourceData; +} + +interface WeaponDataSourceData { + damagePerHit: number; + attackSpeed: number; +} + +interface WeaponDataSource { + type: "weapon"; + data: WeaponDataSourceData; +} + +interface ArmorDataPropertiesData extends ArmorDataSourceData { + weight: number; +} + +interface ArmorDataProperties { + type: "armor"; + data: ArmorDataPropertiesData; +} + +interface WeaponDataPropertiesData extends WeaponDataSourceData { + damage: number; +} + +interface WeaponDataProperties { + type: "weapon"; + data: WeaponDataPropertiesData; +} + +type MyItemDataSource = ArmorDataSource | WeaponDataSource; +type MyItemDataProperties = ArmorDataProperties | WeaponDataProperties; + +declare global { + interface DataConfig { + Item: MyItemDataProperties; + } + + interface SourceConfig { + Item: MyItemDataSource; + } +} + +// @ts-expect-error - ItemData requires data. +new foundry.data.ItemData(); + +// @ts-expect-error - ItemData requires a name and a type. +new foundry.data.ItemData({}); + +// @ts-expect-error - "foo" is not a configured type for an Item. +new foundry.data.ItemData({ name: "Some Item With Wrong Type", type: "foo" }); + +const itemData = new foundry.data.ItemData({ name: "Some Item", type: "weapon" }); + +expectTypeOf(itemData).toEqualTypeOf(); +expectTypeOf(itemData.type).toEqualTypeOf<"weapon" | "armor">(); +if (itemData._source.type === "armor") { + expectTypeOf(itemData._source.data.armorValue).toEqualTypeOf(); + + // @ts-expect-error - "weight" is not a valid property of ArmorDataSourceData + itemData._source.data.weight; +} else { + expectTypeOf(itemData._source.data.attackSpeed).toEqualTypeOf(); + expectTypeOf(itemData._source.data.damagePerHit).toEqualTypeOf(); + + // @ts-expect-error - "damage" is not a valid property of WeaponDataSourceData + itemData._source.data.damage; +} + +if (itemData.type === "armor") { + expectTypeOf(itemData.data.armorValue).toEqualTypeOf(); + expectTypeOf(itemData.data.weight).toEqualTypeOf(); +} else { + expectTypeOf(itemData.data.attackSpeed).toEqualTypeOf(); + expectTypeOf(itemData.data.damagePerHit).toEqualTypeOf(); + expectTypeOf(itemData.data.damage).toEqualTypeOf(); +} diff --git a/tests/foundry/common/data/data.mjs/journalEntryData.test-d.ts b/tests/foundry/common/data/data.mjs/journalEntryData.test-d.ts new file mode 100644 index 000000000..d288e37db --- /dev/null +++ b/tests/foundry/common/data/data.mjs/journalEntryData.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - A JournalEntryData requires data. +new foundry.data.JournalEntryData(); + +// @ts-expect-error - A JournalEntryData requires a name. +new foundry.data.JournalEntryData({}); + +expectTypeOf(new foundry.data.JournalEntryData({ name: "foo" })).toEqualTypeOf(); diff --git a/tests/foundry/common/data/data.mjs/macroData.test-d.ts b/tests/foundry/common/data/data.mjs/macroData.test-d.ts new file mode 100644 index 000000000..90581791e --- /dev/null +++ b/tests/foundry/common/data/data.mjs/macroData.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - a MacroData requires data. +new foundry.data.MacroData(); + +// @ts-expect-error - a MacroData requires a name. +new foundry.data.MacroData({}); + +expectTypeOf(new foundry.data.MacroData({ name: "foo" })).toEqualTypeOf(); diff --git a/test-d/foundry/common/data/data.mjs/measuredTemplateData.test-d.ts b/tests/foundry/common/data/data.mjs/measuredTemplateData.test-d.ts similarity index 53% rename from test-d/foundry/common/data/data.mjs/measuredTemplateData.test-d.ts rename to tests/foundry/common/data/data.mjs/measuredTemplateData.test-d.ts index 214c8075b..35df4aa8d 100644 --- a/test-d/foundry/common/data/data.mjs/measuredTemplateData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/measuredTemplateData.test-d.ts @@ -1,13 +1,21 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; const scene = new Scene({ name: "My scene" }); -expectError(new foundry.data.MeasuredTemplateData()); -expectError(new foundry.data.MeasuredTemplateData({ x: 100, y: 100 })); -expectType(new foundry.data.MeasuredTemplateData({ x: 100, y: 100 }, scene)); -expectType(new foundry.data.MeasuredTemplateData({}, scene)); -expectType(new foundry.data.MeasuredTemplateData(undefined, scene)); -expectType( +// @ts-expect-error - A MeasuredTemplateData requires data. +new foundry.data.MeasuredTemplateData(); + +// @ts-expect-error - A MeasuredTemplateData requires data with an x and y property and a scene. +new foundry.data.MeasuredTemplateData({ x: 100, y: 100 }); + +expectTypeOf( + new foundry.data.MeasuredTemplateData({ x: 100, y: 100 }, scene), +).toEqualTypeOf(); +expectTypeOf(new foundry.data.MeasuredTemplateData({}, scene)).toEqualTypeOf(); +expectTypeOf( + new foundry.data.MeasuredTemplateData(undefined, scene), +).toEqualTypeOf(); +expectTypeOf( new foundry.data.MeasuredTemplateData( { _id: null, @@ -25,8 +33,8 @@ expectType( }, scene, ), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.MeasuredTemplateData( { _id: undefined, @@ -44,9 +52,9 @@ expectType( }, scene, ), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.MeasuredTemplateData( { _id: "10", @@ -64,4 +72,4 @@ expectType( }, scene, ), -); +).toEqualTypeOf(); diff --git a/test-d/foundry/common/data/data.mjs/noteData.test-d.ts b/tests/foundry/common/data/data.mjs/noteData.test-d.ts similarity index 66% rename from test-d/foundry/common/data/data.mjs/noteData.test-d.ts rename to tests/foundry/common/data/data.mjs/noteData.test-d.ts index 4aba31aff..bafdfa88b 100644 --- a/test-d/foundry/common/data/data.mjs/noteData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/noteData.test-d.ts @@ -1,10 +1,10 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; -expectType(new foundry.data.NoteData()); +expectTypeOf(new foundry.data.NoteData()).toEqualTypeOf(); -expectType(new foundry.data.NoteData({})); +expectTypeOf(new foundry.data.NoteData({})).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.NoteData({ _id: undefined, entryId: undefined, @@ -20,9 +20,9 @@ expectType( textColor: undefined, flags: undefined, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.NoteData({ _id: null, entryId: null, @@ -38,9 +38,9 @@ expectType( textColor: null, flags: null, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.NoteData({ _id: "bfeabfiea", entryId: "bebfegibefaei", @@ -56,6 +56,7 @@ expectType( textColor: "#FF0000", flags: {}, }), -); +).toEqualTypeOf(); -expectError(new foundry.data.NoteData({ textAnchor: 999 })); +// @ts-expect-error - A textAnchor cannot be an arbitrary number. +new foundry.data.NoteData({ textAnchor: 999 }); diff --git a/tests/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts b/tests/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts new file mode 100644 index 000000000..b48a099e0 --- /dev/null +++ b/tests/foundry/common/data/data.mjs/prototypeTokenData.test-d.ts @@ -0,0 +1,7 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(new foundry.data.PrototypeTokenData()).toEqualTypeOf(); +expectTypeOf(new foundry.data.PrototypeTokenData({})).toEqualTypeOf(); +expectTypeOf(new foundry.data.PrototypeTokenData({ name: "foo" })).toEqualTypeOf(); +expectTypeOf(new foundry.data.PrototypeTokenData({ name: "foo" }).actorLink).toEqualTypeOf(); +expectTypeOf(new foundry.data.PrototypeTokenData({ name: "foo" }).bar1.attribute).toEqualTypeOf(); diff --git a/test-d/foundry/common/data/data.mjs/sceneData.test-d.ts b/tests/foundry/common/data/data.mjs/sceneData.test-d.ts similarity index 82% rename from test-d/foundry/common/data/data.mjs/sceneData.test-d.ts rename to tests/foundry/common/data/data.mjs/sceneData.test-d.ts index dd3388143..dfe585270 100644 --- a/test-d/foundry/common/data/data.mjs/sceneData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/sceneData.test-d.ts @@ -1,9 +1,13 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; -expectError(new foundry.data.SceneData()); -expectError(new foundry.data.SceneData({})); -expectType(new foundry.data.SceneData({ name: "A long expected journey" })); -expectType( +// @ts-expect-error A SceneData requires data. +new foundry.data.SceneData(); + +// @ts-expect-error A SceneData requires a name. +new foundry.data.SceneData({}); + +expectTypeOf(new foundry.data.SceneData({ name: "A long expected journey" })).toEqualTypeOf(); +expectTypeOf( new foundry.data.SceneData({ _id: undefined, name: "A long expected journey", @@ -50,8 +54,8 @@ expectType( permission: undefined, flags: undefined, }), -); -expectType( +).toEqualTypeOf(); +expectTypeOf( new foundry.data.SceneData({ _id: null, name: "A long expected journey", @@ -98,4 +102,4 @@ expectType( permission: null, flags: null, }), -); +).toEqualTypeOf(); diff --git a/tests/foundry/common/data/data.mjs/settingData.test-d.ts b/tests/foundry/common/data/data.mjs/settingData.test-d.ts new file mode 100644 index 000000000..79d88f35d --- /dev/null +++ b/tests/foundry/common/data/data.mjs/settingData.test-d.ts @@ -0,0 +1,22 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error A SettingData requires data. +new foundry.data.SettingData(); + +// @ts-expect-error A SettingData requires a key and value. +new foundry.data.SettingData({}); + +// @ts-expect-error Key must contain a period. +new foundry.data.SettingData({ key: "foo", value: "bar" }); + +expectTypeOf(new foundry.data.SettingData({ key: "foo.bar", value: "bar" })).toEqualTypeOf(); + +const namespace = "foo"; +const key = "bar"; + +expectTypeOf( + new foundry.data.SettingData({ key: `${namespace}.${key}`, value: "bar" }), +).toEqualTypeOf(); + +// @ts-expect-error This key contains a period but Typescript doesn't infer that and so it should error. +new foundry.data.SettingData({ key: namespace + "." + key, value: "bar" }); diff --git a/test-d/foundry/common/data/data.mjs/tileData.test-d.ts b/tests/foundry/common/data/data.mjs/tileData.test-d.ts similarity index 67% rename from test-d/foundry/common/data/data.mjs/tileData.test-d.ts rename to tests/foundry/common/data/data.mjs/tileData.test-d.ts index 8129ddcaa..4d6f5a165 100644 --- a/test-d/foundry/common/data/data.mjs/tileData.test-d.ts +++ b/tests/foundry/common/data/data.mjs/tileData.test-d.ts @@ -1,10 +1,10 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; -expectType(new foundry.data.TileData()); +expectTypeOf(new foundry.data.TileData()).toEqualTypeOf(); -expectType(new foundry.data.TileData({})); +expectTypeOf(new foundry.data.TileData({})).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.TileData({ _id: undefined, img: undefined, @@ -23,9 +23,9 @@ expectType( video: undefined, flags: undefined, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.TileData({ _id: null, img: null, @@ -44,9 +44,9 @@ expectType( video: null, flags: null, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.TileData({ _id: "BGBEITBTEIGE", img: "path/to/some/image.png", @@ -72,22 +72,21 @@ expectType( }, flags: {}, }), -); +).toEqualTypeOf(); -expectType( +expectTypeOf( new foundry.data.TileData({ occlusion: {}, }), -); +).toEqualTypeOf(); -expectError( - new foundry.data.TileData({ - occlusion: { mode: 999 }, - }), -); +new foundry.data.TileData({ + // @ts-expect-error mode cannot be an arbitrary number. + occlusion: { mode: 999 }, +}); -expectType( +expectTypeOf( new foundry.data.TileData({ video: {}, }), -); +).toEqualTypeOf(); diff --git a/tests/foundry/common/data/data.mjs/userData.test-d.ts b/tests/foundry/common/data/data.mjs/userData.test-d.ts new file mode 100644 index 000000000..851aff69c --- /dev/null +++ b/tests/foundry/common/data/data.mjs/userData.test-d.ts @@ -0,0 +1,17 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error a UserData requires data. +new foundry.data.UserData(); + +// @ts-expect-error a UserData requires a name. +new foundry.data.UserData({}); + +expectTypeOf(new foundry.data.UserData({ name: "foo" })).toEqualTypeOf(); +expectTypeOf(new foundry.data.UserData({ name: "foo", hotbar: { 1: "foo" } })).toEqualTypeOf(); +expectTypeOf(new foundry.data.UserData({ name: "foo", hotbar: { "1": "foo" } })).toEqualTypeOf(); +expectTypeOf( + new foundry.data.UserData({ name: "foo", hotbar: { ["1"]: "foo" } }), +).toEqualTypeOf(); + +// @ts-expect-error foo is not a number or a numeric string +new foundry.data.UserData({ name: "foo", hotbar: { foo: "foo" } }); diff --git a/tests/foundry/common/data/data.mjs/wallData.test-d.ts b/tests/foundry/common/data/data.mjs/wallData.test-d.ts new file mode 100644 index 000000000..aabbc7a9a --- /dev/null +++ b/tests/foundry/common/data/data.mjs/wallData.test-d.ts @@ -0,0 +1,95 @@ +import { expectTypeOf } from "vitest"; + +// @ts-expect-error - a WallData requires data. +new foundry.data.WallData(); + +// @ts-expect-error - a WallData requires c (coordinates). +new foundry.data.WallData({}); + +// @ts-expect-error - a WallData requires c (coordinates) and must have 4 values. +new foundry.data.WallData({ c: [10, 20] }); + +expectTypeOf(new foundry.data.WallData({ c: [10, 20, 30, 40] })).toEqualTypeOf(); +expectTypeOf( + new foundry.data.WallData({ + _id: null, + c: [10, 20, 30, 40], + light: null, + move: null, + sight: null, + sound: null, + dir: null, + door: null, + ds: null, + flags: null, + }), +).toEqualTypeOf(); +expectTypeOf( + new foundry.data.WallData({ + _id: undefined, + c: [10, 20, 30, 40], + light: undefined, + move: undefined, + sight: undefined, + sound: undefined, + dir: undefined, + door: undefined, + ds: undefined, + flags: undefined, + }), +).toEqualTypeOf(); +expectTypeOf( + new foundry.data.WallData({ + c: [10, 20, 30, 40], + light: foundry.CONST.WALL_SENSE_TYPES.NORMAL, + move: foundry.CONST.WALL_MOVEMENT_TYPES.NORMAL, + sight: foundry.CONST.WALL_SENSE_TYPES.NORMAL, + sound: foundry.CONST.WALL_SENSE_TYPES.NORMAL, + dir: foundry.CONST.WALL_DIRECTIONS.BOTH, + door: foundry.CONST.WALL_DOOR_TYPES.NONE, + ds: foundry.CONST.WALL_DOOR_STATES.CLOSED, + flags: {}, + }), +).toEqualTypeOf(); + +new foundry.data.WallData({ + c: [10, 20, 30, 40], + // @ts-expect-error - light can't be an arbitrary number + light: 9999, +}); + +new foundry.data.WallData({ + c: [10, 20, 30, 40], + // @ts-expect-error - move can't be an arbitrary number + move: 9999, +}); + +new foundry.data.WallData({ + c: [10, 20, 30, 40], + // @ts-expect-error - sight can't be an arbitrary number + sight: 9999, +}); + +new foundry.data.WallData({ + c: [10, 20, 30, 40], + // @ts-expect-error - sound can't be an arbitrary number + sound: 9999, +}); + +new foundry.data.WallData({ + c: [10, 20, 30, 40], + // @ts-expect-error - dir can't be an arbitrary number + dir: 9999, +}); + +new foundry.data.WallData({ + c: [10, 20, 30, 40], + // @ts-expect-error - door can't be an arbitrary number + door: 9999, +}); + +new foundry.data.WallData({ + c: [10, 20, 30, 40], + // @ts-expect-error - ds can't be an arbitrary number + ds: 9999, +}); diff --git a/tests/foundry/common/documents.mjs/baseActiveEffect.test-d.ts b/tests/foundry/common/documents.mjs/baseActiveEffect.test-d.ts new file mode 100644 index 000000000..8b9a290df --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseActiveEffect.test-d.ts @@ -0,0 +1,16 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseActiveEffect.create({})).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseActiveEffect.createDocuments([])).toEqualTypeOf< + Promise[]> +>(); +expectTypeOf(foundry.documents.BaseActiveEffect.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseActiveEffect.deleteDocuments([])).toEqualTypeOf>(); + +const activeEffect = await foundry.documents.BaseActiveEffect.create({}, { temporary: true }); +if (activeEffect) { + expectTypeOf(activeEffect.data).toEqualTypeOf(); + expectTypeOf(activeEffect.parent).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseActor.test-d.ts b/tests/foundry/common/documents.mjs/baseActor.test-d.ts new file mode 100644 index 000000000..944ff7d24 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseActor.test-d.ts @@ -0,0 +1,120 @@ +import { expectTypeOf } from "vitest"; + +import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; +import type { ActiveEffectDataSource } from "../../../../src/foundry/common/data/data.mjs/activeEffectData.js"; +import type { EffectDurationDataProperties } from "../../../../src/foundry/common/data/data.mjs/effectDurationData.js"; + +const baseActor = new foundry.documents.BaseActor(); +expectTypeOf(baseActor.effects).toEqualTypeOf>(); +expectTypeOf(baseActor.items).toEqualTypeOf>(); +expectTypeOf(baseActor.data._source.effects[0]).toEqualTypeOf(); +expectTypeOf(baseActor.data._source.effects[0].duration).toEqualTypeOf(); + +interface CharacterDataSourceData { + health: number; +} + +interface CharacterFlags { + "my-module": { + known: boolean; + xp: number; + }; +} + +interface CharacterDataSource { + type: "character"; + data: CharacterDataSourceData; + flags: CharacterFlags; +} + +interface CharacterDataPropertiesData extends CharacterDataSourceData { + movement: number; +} + +interface CharacterDataProperties { + type: "character"; + data: CharacterDataPropertiesData; + flags: CharacterFlags; +} + +interface NPCDataSourceData { + challenge: number; + faction: string; +} + +interface NPCFlags { + "my-module": { + "hidden-name": string; + known: boolean; + }; +} + +interface NPCDataSource { + type: "npc"; + data: NPCDataSourceData; + flags: NPCFlags; +} + +interface NPCDataPropertiesData extends NPCDataSourceData { + damage: number; +} + +interface NPCDataProperties { + type: "npc"; + data: NPCDataPropertiesData; + flags: NPCFlags; +} + +type MyActorDataSource = CharacterDataSource | NPCDataSource; +type MyActorDataProperties = CharacterDataProperties | NPCDataProperties; + +declare global { + interface DataConfig { + Actor: MyActorDataProperties; + } + + interface SourceConfig { + Actor: MyActorDataSource; + } +} + +expectTypeOf(baseActor.data.type).toEqualTypeOf<"character" | "npc">(); +expectTypeOf(baseActor.items.get("", { strict: true }).parent).toEqualTypeOf(); + +if (baseActor.data._source.type === "character") { + expectTypeOf(baseActor.data._source.data.health).toEqualTypeOf(); + + // @ts-expect-error "movement" is not a valid property of CharacterDataSourceData. + baseActor.data._source.data.movement; +} else { + expectTypeOf(baseActor.data._source.data.faction).toEqualTypeOf(); + expectTypeOf(baseActor.data._source.data.challenge).toEqualTypeOf(); + + // @ts-expect-error "damage" is not a valid property of NPCDataSourceData. + baseActor.data._source.data.damage; +} + +if (baseActor.data.type === "character") { + expectTypeOf(baseActor.data.data.health).toEqualTypeOf(); + expectTypeOf(baseActor.data.data.movement).toEqualTypeOf(); +} else { + expectTypeOf(baseActor.data.data.faction).toEqualTypeOf(); + expectTypeOf(baseActor.data.data.challenge).toEqualTypeOf(); + expectTypeOf(baseActor.data.data.damage).toEqualTypeOf(); +} + +// Flags for Actor, Items, Card, and Cards documents can be configured via the SourceConfig. This is tested here. +// For configuring flags for actors and items via FlagConfig please have a look into baseItem.test-d.ts. +// shared flags are available +expectTypeOf(baseActor.getFlag("my-module", "known")).toEqualTypeOf(); +// non shared flags are not available +expectTypeOf(baseActor.getFlag("my-module", "xp")).toEqualTypeOf(); +expectTypeOf(baseActor.getFlag("my-module", "hidden-name")).toEqualTypeOf(); +// non shared flags are also not available if the type is known +if (baseActor.data._source.type === "character") { + expectTypeOf(baseActor.getFlag("my-module", "xp")).toEqualTypeOf(); +} +if (baseActor.data.type === "character") { + expectTypeOf(baseActor.getFlag("my-module", "xp")).toEqualTypeOf(); +} +expectTypeOf(baseActor.documentName).toEqualTypeOf<"Actor">(); diff --git a/test-d/foundry/common/documents.mjs/baseCard.test-d.ts b/tests/foundry/common/documents.mjs/baseCard.test-d.ts similarity index 58% rename from test-d/foundry/common/documents.mjs/baseCard.test-d.ts rename to tests/foundry/common/documents.mjs/baseCard.test-d.ts index 0011bfeb9..02a8f3355 100644 --- a/test-d/foundry/common/documents.mjs/baseCard.test-d.ts +++ b/tests/foundry/common/documents.mjs/baseCard.test-d.ts @@ -1,9 +1,9 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; import type { CardFaceDataSource } from "../../../../src/foundry/common/data/data.mjs/cardFaceData"; const baseCard = new foundry.documents.BaseCard(); -expectType(baseCard.data._source.faces[0]); +expectTypeOf(baseCard.data._source.faces[0]).toEqualTypeOf(); interface OldCardDataSourceData { condition: "grubby"; @@ -72,36 +72,40 @@ declare global { } } -expectType<"old" | "uno">(baseCard.data.type); -expectType(baseCard.parent); +expectTypeOf(baseCard.data.type).toEqualTypeOf<"old" | "uno">(); +expectTypeOf(baseCard.parent).toEqualTypeOf(); if (baseCard.data._source.type === "old") { - expectType<"grubby">(baseCard.data._source.data.condition); - expectError(baseCard.data._source.data.age); + expectTypeOf(baseCard.data._source.data.condition).toEqualTypeOf<"grubby">(); + + // @ts-expect-error - "age" is not a property of OldCardDataSourceData. + baseCard.data._source.data.age; } else { - expectType(baseCard.data._source.data.special); - expectError(baseCard.data._source.data.color); + expectTypeOf(baseCard.data._source.data.special).toEqualTypeOf(); + + // @ts-expect-error - "color" is not a property of UnoCardDataSourceData. + baseCard.data._source.data.color; } if (baseCard.data.type === "old") { - expectType<"grubby">(baseCard.data.data.condition); - expectType(baseCard.data.data.age); + expectTypeOf(baseCard.data.data.condition).toEqualTypeOf<"grubby">(); + expectTypeOf(baseCard.data.data.age).toEqualTypeOf(); } else { - expectType(baseCard.data.data.special); - expectType(baseCard.data.data.color); + expectTypeOf(baseCard.data.data.special).toEqualTypeOf(); + expectTypeOf(baseCard.data.data.color).toEqualTypeOf(); } // Flags for Actor, Items, Card, and Cards documents can be configured via the SourceConfig. This is tested here. // For configuring flags via FlagConfig please take a look into baseItem.test-d.ts. // shared flags are available -expectType(baseCard.getFlag("my-module", "someProp")); +expectTypeOf(baseCard.getFlag("my-module", "someProp")).toEqualTypeOf(); // non shared flags are not available -expectType(baseCard.getFlag("my-module", "marked")); -expectType(baseCard.getFlag("my-module", "folded")); +expectTypeOf(baseCard.getFlag("my-module", "marked")).toEqualTypeOf(); +expectTypeOf(baseCard.getFlag("my-module", "folded")).toEqualTypeOf(); // non shared flags are also not available if the type is known if (baseCard.data._source.type === "old") { - expectType(baseCard.getFlag("my-module", "marked")); + expectTypeOf(baseCard.getFlag("my-module", "marked")).toEqualTypeOf(); } if (baseCard.data.type === "uno") { - expectType(baseCard.getFlag("my-module", "folded")); + expectTypeOf(baseCard.getFlag("my-module", "folded")).toEqualTypeOf(); } diff --git a/test-d/foundry/common/documents.mjs/baseCards.test-d.ts b/tests/foundry/common/documents.mjs/baseCards.test-d.ts similarity index 50% rename from test-d/foundry/common/documents.mjs/baseCards.test-d.ts rename to tests/foundry/common/documents.mjs/baseCards.test-d.ts index 29bc03bb1..e77df6e09 100644 --- a/test-d/foundry/common/documents.mjs/baseCards.test-d.ts +++ b/tests/foundry/common/documents.mjs/baseCards.test-d.ts @@ -1,13 +1,13 @@ -import { expectError, expectType } from "tsd"; +import { expectTypeOf } from "vitest"; -import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs"; -import type { CardDataSource } from "../../../../src/foundry/common/data/data.mjs/cardData"; -import type { CardFaceDataSource } from "../../../../src/foundry/common/data/data.mjs/cardFaceData"; +import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; +import type { CardDataSource } from "../../../../src/foundry/common/data/data.mjs/cardData.js"; +import type { CardFaceDataSource } from "../../../../src/foundry/common/data/data.mjs/cardFaceData.js"; const baseCards = new foundry.documents.BaseCards(); -expectType>(baseCards.cards); -expectType(baseCards.data._source.cards[0]); -expectType(baseCards.data._source.cards[0].faces[0]); +expectTypeOf(baseCards.cards).toEqualTypeOf>(); +expectTypeOf(baseCards.data._source.cards[0]).toEqualTypeOf(); +expectTypeOf(baseCards.data._source.cards[0].faces[0]).toEqualTypeOf(); interface GermanDeckDataSourceData { mostUsedGame: "Skat"; @@ -58,22 +58,26 @@ declare global { } } -expectType<"french" | "german">(baseCards.data.type); -expectType<"french" | "german">(baseCards.type); -expectType(baseCards.parent); +expectTypeOf(baseCards.data.type).toEqualTypeOf<"french" | "german">(); +expectTypeOf(baseCards.type).toEqualTypeOf<"french" | "german">(); +expectTypeOf(baseCards.parent).toEqualTypeOf(); if (baseCards.data._source.type === "french") { - expectType<"throwing cards">(baseCards.data._source.data.coolUse); - expectError(baseCards.data._source.data.possibleInjuries); + expectTypeOf(baseCards.data._source.data.coolUse).toEqualTypeOf<"throwing cards">(); + + // @ts-expect-error - "possibleInjuries" is not a property of FrenchDeckDataSourceData. + baseCards.data._source.data.possibleInjuries; } else { - expectType<"Skat">(baseCards.data._source.data.mostUsedGame); - expectError(baseCards.data._source.data.mostUsedBy); + expectTypeOf(baseCards.data._source.data.mostUsedGame).toEqualTypeOf<"Skat">(); + + // @ts-expect-error - "mostUsedBy" is not a property of GermanDeckDataSourceData. + baseCards.data._source.data.mostUsedBy; } if (baseCards.data.type === "french") { - expectType<"throwing cards">(baseCards.data.data.coolUse); - expectType<"card stuck in eye">(baseCards.data.data.possibleInjuries); + expectTypeOf(baseCards.data.data.coolUse).toEqualTypeOf<"throwing cards">(); + expectTypeOf(baseCards.data.data.possibleInjuries).toEqualTypeOf<"card stuck in eye">(); } else { - expectType<"Skat">(baseCards.data.data.mostUsedGame); - expectType<"older players">(baseCards.data.data.mostUsedBy); + expectTypeOf(baseCards.data.data.mostUsedGame).toEqualTypeOf<"Skat">(); + expectTypeOf(baseCards.data.data.mostUsedBy).toEqualTypeOf<"older players">(); } diff --git a/tests/foundry/common/documents.mjs/baseChatMessage.test-d.ts b/tests/foundry/common/documents.mjs/baseChatMessage.test-d.ts new file mode 100644 index 000000000..a24e485a9 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseChatMessage.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseChatMessage.create({})).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseChatMessage.createDocuments([])).toEqualTypeOf< + Promise[]> +>(); +expectTypeOf(foundry.documents.BaseChatMessage.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseChatMessage.deleteDocuments([])).toEqualTypeOf>(); + +const chat = await foundry.documents.BaseChatMessage.create({}, { temporary: true }); +if (chat) { + expectTypeOf(chat.data).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseCombat.test-d.ts b/tests/foundry/common/documents.mjs/baseCombat.test-d.ts new file mode 100644 index 000000000..c5532fb19 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseCombat.test-d.ts @@ -0,0 +1,13 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseCombat.create({ scene: "foo", active: true, sort: 1 })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseCombat.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(foundry.documents.BaseCombat.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseCombat.deleteDocuments([])).toEqualTypeOf>(); + +const combat = await foundry.documents.BaseCombat.create({ scene: "foo", active: true }, { temporary: true }); +if (combat) { + expectTypeOf(combat.data).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseCombatant.test-d.ts b/tests/foundry/common/documents.mjs/baseCombatant.test-d.ts new file mode 100644 index 000000000..3cfcd75ed --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseCombatant.test-d.ts @@ -0,0 +1,16 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseCombatant.create({ actorId: "someID", tokenId: "someOtherId" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseCombatant.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(foundry.documents.BaseCombatant.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseCombatant.deleteDocuments([])).toEqualTypeOf>(); + +const combatant = await foundry.documents.BaseCombatant.create( + { name: "Another Combatant", type: "Actor" }, + { temporary: true }, +); +if (combatant) { + expectTypeOf(combatant.data).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseDrawing.test-d.ts b/tests/foundry/common/documents.mjs/baseDrawing.test-d.ts new file mode 100644 index 000000000..801844fb2 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseDrawing.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseDrawing.create({})).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseDrawing.createDocuments([])).toEqualTypeOf< + Promise[]> +>(); +expectTypeOf(foundry.documents.BaseDrawing.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseDrawing.deleteDocuments([])).toEqualTypeOf>(); + +const drawing = await foundry.documents.BaseDrawing.create({}, { temporary: true }); +if (drawing) { + expectTypeOf(drawing.data).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseFogExploration.test-d.ts b/tests/foundry/common/documents.mjs/baseFogExploration.test-d.ts new file mode 100644 index 000000000..de2e8fdab --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseFogExploration.test-d.ts @@ -0,0 +1,15 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(new foundry.documents.BaseFogExploration()).toEqualTypeOf(); +expectTypeOf(new foundry.documents.BaseFogExploration({})).toEqualTypeOf(); +expectTypeOf(foundry.documents.BaseFogExploration.create({})).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseFogExploration.createDocuments()).toEqualTypeOf< + Promise[]> +>(); +expectTypeOf(foundry.documents.BaseFogExploration.updateDocuments()).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseFogExploration.deleteDocuments()).toEqualTypeOf>(); + +const folder = new foundry.documents.BaseFogExploration(); +expectTypeOf(folder.data).toEqualTypeOf(); diff --git a/tests/foundry/common/documents.mjs/baseFolder.test-d.ts b/tests/foundry/common/documents.mjs/baseFolder.test-d.ts new file mode 100644 index 000000000..538e92073 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseFolder.test-d.ts @@ -0,0 +1,16 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseFolder.create({ name: "Some Folder", type: "Item" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseFolder.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(foundry.documents.BaseFolder.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseFolder.deleteDocuments([])).toEqualTypeOf>(); + +const folder = await foundry.documents.BaseFolder.create( + { name: "Another Folder", type: "Actor" }, + { temporary: true }, +); +if (folder) { + expectTypeOf(folder.data).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseItem.test-d.ts b/tests/foundry/common/documents.mjs/baseItem.test-d.ts new file mode 100644 index 000000000..e9b2e45c8 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseItem.test-d.ts @@ -0,0 +1,113 @@ +import { expectTypeOf } from "vitest"; + +import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; +import type { BaseItem } from "../../../../src/foundry/common/documents.mjs/index.js"; +import type { ActiveEffectDataSource } from "../../../../src/foundry/common/data/data.mjs/activeEffectData.js"; +import type { EffectDurationDataProperties } from "../../../../src/foundry/common/data/data.mjs/effectDurationData.js"; + +const baseItem = new foundry.documents.BaseItem(); +expectTypeOf(baseItem.effects).toEqualTypeOf>(); +expectTypeOf(baseItem.data._source.effects[0]).toEqualTypeOf(); +expectTypeOf(baseItem.data._source.effects[0].duration).toEqualTypeOf(); + +interface ArmorDataSourceData { + armorValue: number; +} + +interface ArmorDataSource { + type: "armor"; + data: ArmorDataSourceData; +} + +interface WeaponDataSourceData { + damagePerHit: number; + attackSpeed: number; +} + +interface WeaponDataSource { + type: "weapon"; + data: WeaponDataSourceData; +} + +interface ArmorDataPropertiesData extends ArmorDataSourceData { + weight: number; +} + +interface ArmorDataProperties { + type: "armor"; + data: ArmorDataPropertiesData; +} + +interface WeaponDataPropertiesData extends WeaponDataSourceData { + damage: number; +} + +interface WeaponDataProperties { + type: "weapon"; + data: WeaponDataPropertiesData; +} + +type MyItemDataSource = ArmorDataSource | WeaponDataSource; +type MyItemDataProperties = ArmorDataProperties | WeaponDataProperties; + +declare global { + interface DataConfig { + Item: MyItemDataProperties; + } + + interface SourceConfig { + Item: MyItemDataSource; + } +} + +expectTypeOf(baseItem.data.type).toEqualTypeOf<"weapon" | "armor">(); +expectTypeOf(baseItem.parent?.items.get("", { strict: true })).toEqualTypeOf(); + +if (baseItem.data._source.type === "armor") { + expectTypeOf(baseItem.data._source.data.armorValue).toEqualTypeOf(); + + // @ts-expect-error - "weight" is not a valid property of ArmorDataSourceData + baseItem.data._source.data.weight; +} else { + expectTypeOf(baseItem.data._source.data.attackSpeed).toEqualTypeOf(); + expectTypeOf(baseItem.data._source.data.damagePerHit).toEqualTypeOf(); + + // @ts-expect-error - "damage" is not a valid property of WeaponDataSourceData + baseItem.data._source.data.damage; +} + +if (baseItem.data.type === "armor") { + expectTypeOf(baseItem.data.data.armorValue).toEqualTypeOf(); + expectTypeOf(baseItem.data.data.weight).toEqualTypeOf(); +} else { + expectTypeOf(baseItem.data.data.attackSpeed).toEqualTypeOf(); + expectTypeOf(baseItem.data.data.damagePerHit).toEqualTypeOf(); + expectTypeOf(baseItem.data.data.damage).toEqualTypeOf(); +} + +// Flags for Actor, Item, Card, and Cards documents can be configured via the FlagConfig. This is tested here. +// For configuring flags for actors and items via SourceConfig please have a look into baseActor.test-d.ts. +declare global { + interface FlagConfig { + Item: { + "my-system": { + countable: boolean; + }; + }; + } +} +expectTypeOf(baseItem.data.flags["my-system"]).toEqualTypeOf<{ countable: boolean }>(); + +expectTypeOf(baseItem.getFlag("my-system", "countable")).toEqualTypeOf(); +expectTypeOf(baseItem.getFlag("my-system", "unknown-key")).toEqualTypeOf(); +expectTypeOf(baseItem.getFlag("another-system", "value")).toEqualTypeOf(); + +expectTypeOf(baseItem.setFlag("my-system", "countable", true)).toEqualTypeOf>(); + +// @ts-expect-error - my-system.countable is a boolean not a number. +baseItem.setFlag("my-system", "countable", 2); + +// @ts-expect-error - my-system.unknown-key does not exist. +baseItem.setFlag("my-system", "unknown-key", 2); + +expectTypeOf(baseItem.setFlag("another-system", "value", true)).toEqualTypeOf>(); diff --git a/tests/foundry/common/documents.mjs/baseJournalEntry.test-d.ts b/tests/foundry/common/documents.mjs/baseJournalEntry.test-d.ts new file mode 100644 index 000000000..86e26f199 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseJournalEntry.test-d.ts @@ -0,0 +1,18 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseJournalEntry.create({ name: "Some JournalEntry" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseJournalEntry.createDocuments([])).toEqualTypeOf< + Promise[]> +>(); +expectTypeOf(foundry.documents.BaseJournalEntry.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseJournalEntry.deleteDocuments([])).toEqualTypeOf>(); + +const journalEntry = await foundry.documents.BaseJournalEntry.create( + { name: "Another JournalEntry" }, + { temporary: true }, +); +if (journalEntry) { + expectTypeOf(journalEntry.data).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts b/tests/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts new file mode 100644 index 000000000..ea4541a7b --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseMeasuredTemplate.test-d.ts @@ -0,0 +1,6 @@ +import { expectTypeOf } from "vitest"; + +const template = new foundry.documents.BaseMeasuredTemplate(); +expectTypeOf(template.data._id).toEqualTypeOf(); +expectTypeOf(template.data.t).toEqualTypeOf<"circle" | "cone" | "rect" | "ray">(); +expectTypeOf(template.parent).toEqualTypeOf(); diff --git a/tests/foundry/common/documents.mjs/baseScene.test-d.ts b/tests/foundry/common/documents.mjs/baseScene.test-d.ts new file mode 100644 index 000000000..eaacbf1b0 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseScene.test-d.ts @@ -0,0 +1,86 @@ +import type EmbeddedCollection from "../../../../src/foundry/common/abstract/embedded-collection.mjs.js"; + +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseScene.getDimensions()).toEqualTypeOf<{ + distance: number; + height: number; + paddingX: number; + paddingY: number; + ratio: number; + sceneHeight: number; + sceneWidth: number; + shiftX: number; + shiftY: number; + size: number; + width: number; +}>(); + +expectTypeOf(foundry.documents.BaseScene.getDimensions({})).toEqualTypeOf<{ + distance: number; + height: number; + paddingX: number; + paddingY: number; + ratio: number; + sceneHeight: number; + sceneWidth: number; + shiftX: number; + shiftY: number; + size: number; + width: number; +}>(); + +expectTypeOf( + foundry.documents.BaseScene.getDimensions({ + width: 100, + height: 200, + gridDistance: 100, + padding: 10, + shiftX: 0, + shiftY: 0, + }), +).toEqualTypeOf<{ + distance: number; + height: number; + paddingX: number; + paddingY: number; + ratio: number; + sceneHeight: number; + sceneWidth: number; + shiftX: number; + shiftY: number; + size: number; + width: number; +}>(); + +// @ts-expect-error - A BaseScene requires data. +foundry.documents.BaseScene.create(); + +// @ts-expect-error - A BaseScene requires a name. +foundry.documents.BaseScene.create({}); + +expectTypeOf(foundry.documents.BaseScene.create({ name: "My scene" })).toEqualTypeOf< + Promise | undefined> +>(); + +const myScene = await foundry.documents.BaseScene.create({ name: "My second scene" }, { temporary: true }); +if (myScene) { + expectTypeOf(myScene.data).toEqualTypeOf(); +} + +// @ts-expect-error - A BaseScene requires a name. +new foundry.documents.BaseScene({}); + +const scene = new foundry.documents.BaseScene({ name: "My third scene" }); +expectTypeOf(scene).toEqualTypeOf(); + +expectTypeOf(scene.drawings).toEqualTypeOf>(); +expectTypeOf(scene.lights).toEqualTypeOf>(); +expectTypeOf(scene.notes).toEqualTypeOf>(); +expectTypeOf(scene.sounds).toEqualTypeOf>(); +expectTypeOf(scene.templates).toEqualTypeOf< + EmbeddedCollection +>(); +expectTypeOf(scene.tokens).toEqualTypeOf>(); +expectTypeOf(scene.tiles).toEqualTypeOf>(); +expectTypeOf(scene.walls).toEqualTypeOf>(); diff --git a/tests/foundry/common/documents.mjs/baseSetting.test-d.ts b/tests/foundry/common/documents.mjs/baseSetting.test-d.ts new file mode 100644 index 000000000..ce1e17f45 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseSetting.test-d.ts @@ -0,0 +1,16 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseSetting.create({ key: "foo.bar", value: "bar" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseSetting.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(foundry.documents.BaseSetting.updateDocuments([])).toEqualTypeOf>(); +expectTypeOf(foundry.documents.BaseSetting.deleteDocuments([])).toEqualTypeOf>(); + +const settingData = await foundry.documents.BaseSetting.create( + { key: "fizz.buzz", value: "buzz" }, + { temporary: true }, +); +if (settingData) { + expectTypeOf(settingData.data).toEqualTypeOf(); +} diff --git a/tests/foundry/common/documents.mjs/baseUser.test-d.ts b/tests/foundry/common/documents.mjs/baseUser.test-d.ts new file mode 100644 index 000000000..bbeef42ee --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseUser.test-d.ts @@ -0,0 +1,111 @@ +import type { ConfiguredDocumentClass } from "../../../../src/types/helperTypes"; +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.documents.BaseUser.create({ name: "SomeUser" })).toEqualTypeOf< + Promise | undefined> +>(); +expectTypeOf(foundry.documents.BaseUser.createDocuments([])).toEqualTypeOf[]>>(); +expectTypeOf(foundry.documents.BaseUser.updateDocuments([])).toEqualTypeOf< + Promise>[]> +>(); +expectTypeOf(foundry.documents.BaseUser.deleteDocuments([])).toEqualTypeOf< + Promise>[]> +>(); + +const user = await foundry.documents.BaseUser.create({ name: "Another User" }, { temporary: true }); +if (user) { + expectTypeOf(user.data).toEqualTypeOf(); +} + +const baseUser = new foundry.documents.BaseUser(); +expectTypeOf(baseUser.hasRole("NONE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole("PLAYER")).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole("TRUSTED")).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole("ASSISTANT")).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole("GAMEMASTER")).toEqualTypeOf(); + +expectTypeOf(baseUser.hasRole(CONST.USER_ROLES.NONE)).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole(CONST.USER_ROLES.PLAYER)).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole(CONST.USER_ROLES.TRUSTED)).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole(CONST.USER_ROLES.ASSISTANT)).toEqualTypeOf(); +expectTypeOf(baseUser.hasRole(CONST.USER_ROLES.GAMEMASTER)).toEqualTypeOf(); + +// @ts-expect-error - "ACTOR_CREATE" is not a valid role. +baseUser.hasRole("ACTOR_CREATE"); + +// @ts-expect-error - -1 is not a valid role. +baseUser.hasRole(-1); + +// @ts-expect-error - 100 is not a valid role. +baseUser.hasRole(100); + +expectTypeOf(baseUser.can("NONE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("PLAYER")).toEqualTypeOf(); +expectTypeOf(baseUser.can("TRUSTED")).toEqualTypeOf(); +expectTypeOf(baseUser.can("ASSISTANT")).toEqualTypeOf(); +expectTypeOf(baseUser.can("GAMEMASTER")).toEqualTypeOf(); + +expectTypeOf(baseUser.can(CONST.USER_ROLES.NONE)).toEqualTypeOf(); +expectTypeOf(baseUser.can(CONST.USER_ROLES.PLAYER)).toEqualTypeOf(); +expectTypeOf(baseUser.can(CONST.USER_ROLES.TRUSTED)).toEqualTypeOf(); +expectTypeOf(baseUser.can(CONST.USER_ROLES.ASSISTANT)).toEqualTypeOf(); +expectTypeOf(baseUser.can(CONST.USER_ROLES.GAMEMASTER)).toEqualTypeOf(); + +expectTypeOf(baseUser.can("ACTOR_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("BROADCAST_AUDIO")).toEqualTypeOf(); +expectTypeOf(baseUser.can("BROADCAST_VIDEO")).toEqualTypeOf(); +expectTypeOf(baseUser.can("DRAWING_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("ITEM_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("FILES_BROWSE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("FILES_UPLOAD")).toEqualTypeOf(); +expectTypeOf(baseUser.can("JOURNAL_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("MACRO_SCRIPT")).toEqualTypeOf(); +expectTypeOf(baseUser.can("MESSAGE_WHISPER")).toEqualTypeOf(); +expectTypeOf(baseUser.can("NOTE_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("SETTINGS_MODIFY")).toEqualTypeOf(); +expectTypeOf(baseUser.can("SHOW_CURSOR")).toEqualTypeOf(); +expectTypeOf(baseUser.can("SHOW_RULER")).toEqualTypeOf(); +expectTypeOf(baseUser.can("TEMPLATE_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("TOKEN_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("TOKEN_CONFIGURE")).toEqualTypeOf(); +expectTypeOf(baseUser.can("WALL_DOORS")).toEqualTypeOf(); + +// @ts-expect-error - -1 is not a valid action. +baseUser.can(-1); + +// @ts-expect-error - 0 is not a valid action. +baseUser.can(100); + +// @ts-expect-error - "SHOW_RULERS" is not a valid action. +baseUser.can("SHOW_RULERS"); + +expectTypeOf(baseUser.hasPermission("ACTOR_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("BROADCAST_AUDIO")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("BROADCAST_VIDEO")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("DRAWING_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("ITEM_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("FILES_BROWSE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("FILES_UPLOAD")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("JOURNAL_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("MACRO_SCRIPT")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("MESSAGE_WHISPER")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("NOTE_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("SETTINGS_MODIFY")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("SHOW_CURSOR")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("SHOW_RULER")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("TEMPLATE_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("TOKEN_CREATE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("TOKEN_CONFIGURE")).toEqualTypeOf(); +expectTypeOf(baseUser.hasPermission("WALL_DOORS")).toEqualTypeOf(); + +// @ts-expect-error - "GAMEMASTER" is not a valid permission. +baseUser.hasPermission("GAMEMASTER"); + +// @ts-expect-error - CONST.USER_ROLES.GAMEMASTER is not a valid permission. +baseUser.hasPermission(CONST.USER_ROLES.GAMEMASTER); + +// @ts-expect-error - 10 is not a valid permission. +baseUser.hasPermission(10); + +// @ts-expect-error - "SHOW_RULERS" is not a valid permission. +baseUser.hasPermission("SHOW_RULERS"); diff --git a/tests/foundry/common/documents.mjs/baseWall.test-d.ts b/tests/foundry/common/documents.mjs/baseWall.test-d.ts new file mode 100644 index 000000000..fb67a1e64 --- /dev/null +++ b/tests/foundry/common/documents.mjs/baseWall.test-d.ts @@ -0,0 +1,12 @@ +export {}; + +declare const scene: Scene; + +// @ts-expect-error - A BaseWall requires data. +new foundry.documents.BaseWall(); + +// @ts-expect-error - A BaseWall requires c (coordinates). +new foundry.documents.BaseWall({}); + +new foundry.documents.BaseWall({ c: [0, 0, 0, 0] }); +new foundry.documents.BaseWall({ c: [0, 0, 0, 0] }, { parent: scene }); diff --git a/tests/foundry/common/primitives/array.mjs.test-d.ts b/tests/foundry/common/primitives/array.mjs.test-d.ts new file mode 100644 index 000000000..9dfe34366 --- /dev/null +++ b/tests/foundry/common/primitives/array.mjs.test-d.ts @@ -0,0 +1,9 @@ +import { expectTypeOf } from "vitest"; +import "../../index"; + +expectTypeOf([["testing"], "test"].deepFlatten()).toEqualTypeOf(); + +expectTypeOf(Array<"a" | "b">().partition((val): val is "b" => val === "b")).toEqualTypeOf<["a"[], "b"[]]>(); +expectTypeOf([1, ""].partition((val): val is string => typeof val === "string")).toEqualTypeOf<[number[], string[]]>(); +expectTypeOf(Array().partition((val): boolean => val.length < 5)).toEqualTypeOf<[string[], string[]]>(); +expectTypeOf(Array().partition((val) => val.length < 5)).toEqualTypeOf<[string[], string[]]>(); diff --git a/tests/foundry/common/primitives/set.mjs.test-d.ts b/tests/foundry/common/primitives/set.mjs.test-d.ts new file mode 100644 index 000000000..666810758 --- /dev/null +++ b/tests/foundry/common/primitives/set.mjs.test-d.ts @@ -0,0 +1,13 @@ +import { expectTypeOf } from "vitest"; +import "../../index"; + +expectTypeOf(new Set().filter((value): value is string => typeof value === "string")).toEqualTypeOf< + Set +>(); +expectTypeOf(new Set<"a" | "b">().filter((value): value is "a" => value === "a")).toEqualTypeOf>(); + +expectTypeOf(new Set().find((value) => value > 5)).toEqualTypeOf(); +expectTypeOf(new Set().find((value): value is number => typeof value === "number")).toEqualTypeOf< + number | undefined +>(); +expectTypeOf(new Set<"a" | "b">().find((value): value is "a" => value === "a")).toEqualTypeOf<"a" | undefined>(); diff --git a/tests/foundry/common/primitives/string.mjs.test-d.ts b/tests/foundry/common/primitives/string.mjs.test-d.ts new file mode 100644 index 000000000..54d67de83 --- /dev/null +++ b/tests/foundry/common/primitives/string.mjs.test-d.ts @@ -0,0 +1,12 @@ +import { expectTypeOf } from "vitest"; +import "../../index"; + +expectTypeOf("foo".capitalize()).toEqualTypeOf<"Foo">(); +expectTypeOf("FOO".capitalize()).toEqualTypeOf<"FOO">(); +expectTypeOf("foo bar".capitalize()).toEqualTypeOf<"Foo bar">(); +expectTypeOf("FOO BAR".capitalize()).toEqualTypeOf<"FOO BAR">(); + +expectTypeOf("foo".titleCase()).toEqualTypeOf<"Foo">(); +expectTypeOf("FOO".titleCase()).toEqualTypeOf<"Foo">(); +expectTypeOf("foo bar".titleCase()).toEqualTypeOf<"Foo Bar">(); +expectTypeOf("FOO BAR".titleCase()).toEqualTypeOf<"Foo Bar">(); diff --git a/tests/foundry/common/utils/collection.mjs.test-d.ts b/tests/foundry/common/utils/collection.mjs.test-d.ts new file mode 100644 index 000000000..596c9a8eb --- /dev/null +++ b/tests/foundry/common/utils/collection.mjs.test-d.ts @@ -0,0 +1,23 @@ +import { expectTypeOf } from "vitest"; +import "../../../index"; + +const c = new Collection(); + +expectTypeOf(c.get("")).toEqualTypeOf(); +expectTypeOf(c.get("", { strict: false })).toEqualTypeOf(); +expectTypeOf(c.get("", { strict: true })).toEqualTypeOf(); + +expectTypeOf(c.getName("")).toEqualTypeOf(); +expectTypeOf(c.getName("", { strict: false })).toEqualTypeOf(); +expectTypeOf(c.getName("", { strict: true })).toEqualTypeOf(); + +function isString(e: string | null): e is string { + return typeof e === "string"; +} + +const cn = new Collection(); +expectTypeOf(cn.filter((each) => typeof each === "string")).toEqualTypeOf>(); +expectTypeOf(cn.find((each) => typeof each === "string")).toEqualTypeOf(); + +expectTypeOf(cn.filter(isString)).toEqualTypeOf(); +expectTypeOf(cn.find(isString)).toEqualTypeOf(); diff --git a/tests/foundry/common/utils/helpers.mjs.test-d.ts b/tests/foundry/common/utils/helpers.mjs.test-d.ts new file mode 100644 index 000000000..7bc76806c --- /dev/null +++ b/tests/foundry/common/utils/helpers.mjs.test-d.ts @@ -0,0 +1,429 @@ +import { expectTypeOf, assertType } from "vitest"; +import "../../../global"; + +// benchmark + +declare function functionWithoutParameters(): void; +declare function functionWithParameters(a: number, b: string, c?: boolean): void; +declare function functionWithReturnTypeOtherThanVoid(): number; + +expectTypeOf(foundry.utils.benchmark(functionWithoutParameters, 42)).toEqualTypeOf>(); + +// @ts-expect-error - the function takes no arguments +foundry.utils.benchmark(functionWithoutParameters, 42, "unknown argument"); + +expectTypeOf(foundry.utils.benchmark(functionWithParameters, 42, 1, "", false)).toEqualTypeOf>(); +expectTypeOf(foundry.utils.benchmark(functionWithParameters, 42, 1, "")).toEqualTypeOf>(); + +// @ts-expect-error - the function takes a number and a string +foundry.utils.benchmark(functionWithParameters, 42, 1); + +// @ts-expect-error - the function takes doesn't take three arguments +foundry.utils.benchmark(functionWithParameters, 42, 1, "", "unknown argument"); + +expectTypeOf(foundry.utils.benchmark(functionWithReturnTypeOtherThanVoid, 42)).toEqualTypeOf>(); + +// deepClone + +const complexObject = { + a: "", + b: 0, + toJSON: () => [ + false, + undefined, + { + c: undefined, + d: ((): boolean | symbol => false)(), + e: [true], + f: { g: 0, h: ((): number | undefined => 0)() }, + }, + ], +}; + +expectTypeOf(foundry.utils.deepClone("abc" as string)).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone("abc" as const)).toEqualTypeOf<"abc">(); +expectTypeOf(foundry.utils.deepClone(1 as number)).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(1 as const)).toEqualTypeOf<1>(); +expectTypeOf(foundry.utils.deepClone(1n as bigint)).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(1n as const)).toEqualTypeOf<1n>(); +expectTypeOf(foundry.utils.deepClone(true as const)).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(true as boolean)).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(Symbol("customSymbol"))).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(undefined)).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(null)).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(["a", "b"])).toEqualTypeOf>(); +expectTypeOf(foundry.utils.deepClone(["a", "b"])).toEqualTypeOf>(); +expectTypeOf(foundry.utils.deepClone({ a: "foo", b: 42 })).toEqualTypeOf<{ a: string; b: number }>(); +expectTypeOf(foundry.utils.deepClone(new Date())).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone(complexObject)).toEqualTypeOf(); + +expectTypeOf(foundry.utils.deepClone("abc" as string, { strict: false })).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone("abc" as string, { strict: true })).toEqualTypeOf(); +expectTypeOf(foundry.utils.deepClone("abc" as string, { strict: true as boolean })).toEqualTypeOf(); + +// duplicate + +expectTypeOf(foundry.utils.duplicate("")).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(0)).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate<0 | 1>(0)).toEqualTypeOf<0 | 1>(); + +expectTypeOf(foundry.utils.duplicate<"foo" | "bar">("foo")).toEqualTypeOf<"foo" | "bar">(); + +expectTypeOf(foundry.utils.duplicate(0)).toEqualTypeOf(); + +/* `NaN` will actually be converted to `null` but for ease of use, this is ignored. */ +expectTypeOf(foundry.utils.duplicate(NaN)).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(((): boolean => false)())).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(null)).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(undefined)).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(() => 0)).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(Symbol(""))).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(false as const)).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(((): string | boolean => "")())).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(((): string | number => "")())).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(((): string | null => "")())).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(((): string | undefined => "")())).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(((): string | Function => "")())).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate(((): string | symbol => "")())).toEqualTypeOf(); + +expectTypeOf(foundry.utils.duplicate([""])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([0])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([false, true])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([null])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([undefined])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([() => 0])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([Symbol("")])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([false as const])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate(["", false, true])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate(["", 0])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate(["", null])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate(["", undefined])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate(["", () => 0])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate(["", Symbol("")])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([((): "a" | "b" => "a")()])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate([[false, true]])).toEqualTypeOf>>(); + +expectTypeOf(foundry.utils.duplicate([{ a: "" }])).toEqualTypeOf>(); + +expectTypeOf(foundry.utils.duplicate({ a: "" })).toEqualTypeOf<{ a: string }>(); + +expectTypeOf(foundry.utils.duplicate({ a: 0 })).toEqualTypeOf<{ a: number }>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): boolean => false)() })).toEqualTypeOf<{ a: boolean }>(); + +expectTypeOf(foundry.utils.duplicate({ a: null })).toEqualTypeOf<{ a: null }>(); + +expectTypeOf(foundry.utils.duplicate({ a: undefined })).toEqualTypeOf<{}>(); + +expectTypeOf(foundry.utils.duplicate({ a: () => 0 })).toEqualTypeOf<{}>(); + +expectTypeOf(foundry.utils.duplicate({ a: Symbol("") })).toEqualTypeOf<{}>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): string | boolean => "")() })).toEqualTypeOf<{ a: string | boolean }>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): string | number => "")() })).toEqualTypeOf<{ a: string | number }>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): string | null => "")() })).toEqualTypeOf<{ a: string | null }>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): string | undefined => "")() })).toEqualTypeOf<{ + a?: string | undefined; +}>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): string | Function => "")() })).toEqualTypeOf<{ + a?: string | undefined; +}>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): string | symbol => "")() })).toEqualTypeOf<{ a?: string | undefined }>(); + +expectTypeOf(foundry.utils.duplicate({ a: [""] })).toEqualTypeOf<{ a: Array }>(); + +expectTypeOf(foundry.utils.duplicate({ a: { b: "" } })).toEqualTypeOf<{ a: { b: string } }>(); + +expectTypeOf(foundry.utils.duplicate({ a: false as const })).toEqualTypeOf<{ a: false }>(); + +expectTypeOf(foundry.utils.duplicate({ a: ((): "a" | "b" => "a")() })).toEqualTypeOf<{ a: "a" | "b" }>(); + +expectTypeOf(foundry.utils.duplicate({ a: 0, b: "", c: false, toJSON: (): string => "" })).toEqualTypeOf(); + +expectTypeOf( + foundry.utils.duplicate({ a: 0, b: "", c: false, toJSON: () => ({ foo: "", bar: ((): boolean => false)() }) }), +).toEqualTypeOf<{ foo: string; bar: boolean }>(); + +expectTypeOf( + foundry.utils.duplicate({ + a: 0, + b: "", + c: false, + toJSON: () => ({ foo: "", bar: ((): boolean => false)(), toJSON: () => "" }), + }), +).toEqualTypeOf<{ foo: string; bar: boolean }>(); + +expectTypeOf( + foundry.utils.duplicate({ + a: 0, + b: "", + c: false, + toJSON: () => ({ foo: "", bar: { baz: "", toJSON: () => false } }), + }), +).toEqualTypeOf<{ foo: string; bar: false }>(); + +expectTypeOf(foundry.utils.duplicate(complexObject)).toEqualTypeOf< + Array< + | boolean + | null + | { + d?: boolean | undefined; + e: Array; + f: { g: number; h?: number | undefined }; + } + > +>(); + +// isSubclass + +declare class ClassWithNoConstructorParameters {} + +declare class ClassWithConstructorParameters { + constructor(a: number, b: string); +} + +expectTypeOf( + foundry.utils.isSubclass(ClassWithNoConstructorParameters, ClassWithConstructorParameters), +).toEqualTypeOf(); +expectTypeOf( + foundry.utils.isSubclass(ClassWithConstructorParameters, ClassWithNoConstructorParameters), +).toEqualTypeOf(); + +// invertObject +expectTypeOf(foundry.utils.invertObject({ a: 1, b: "foo" } as const)).toEqualTypeOf<{ + readonly 1: "a"; + readonly foo: "b"; +}>(); + +// mergeObject: assertType is used here because of https://github.com/SamVerschueren/tsd/issues/67 +// mergeObject (1): tests from the docs +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "v1" }, { k2: "v2" }, { insertKeys: false })); +assertType<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "v1" }, { k2: "v2" }, { insertKeys: true })); +assertType<{ k1: { i1: string } }>( + foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { insertValues: false }), +); +assertType<{ k1: { i1: string; i2: string } }>( + foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { insertValues: true }), +); + +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "v1" }, { k1: "v2" }, { overwrite: true })); +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "v1" }, { k1: "v2" }, { overwrite: false })); + +assertType<{ k1: { i2: string } }>( + foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { recursive: false }), +); +assertType<{ k1: { i1: string; i2: string } }>( + foundry.utils.mergeObject({ k1: { i1: "v1" } }, { k1: { i2: "v2" } }, { recursive: true }), +); + +// mergeObject (2): more simple tests + +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" })); +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" }, {})); +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" }, { insertKeys: false })); +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: "" }, { insertKeys: true })); + +assertType<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" })); +assertType<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" }, {})); +assertType<{ k1: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" }, { insertKeys: false })); +assertType<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k2: "" }, { insertKeys: true })); + +assertType<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" })); +assertType<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, {})); +assertType<{ k1: number }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { insertKeys: false })); +assertType<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { insertKeys: true })); + +assertType(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: true })); +assertType<{ k1: number; k2: string }>( + foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: false }), +); +assertType(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: true, insertKeys: false })); +assertType(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { enforceTypes: true, insertKeys: true })); + +assertType<{ k1: string; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: false })); +assertType<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: true })); +assertType<{ k1: number; k2: string }>(foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, {})); +assertType<{ k1: string }>( + foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: false, insertKeys: false }), +); +assertType<{ k1: string; k2: string }>( + foundry.utils.mergeObject({ k1: "" }, { k1: 2, k2: "" }, { overwrite: false, insertKeys: true }), +); + +// mergeObject (3): more complex examples +assertType<{ k1: { i1: string; i2: string }; k2: number; k3: number }>( + foundry.utils.mergeObject({ k1: { i1: "foo" }, k2: 2 }, { k1: { i2: "bar" }, k3: 3 }), +); +assertType<{ k1: { i1: string; i2: string; i3: number }; k2: number; k3: number }>( + foundry.utils.mergeObject({ k1: { i1: "foo", i3: { j1: 0 } }, k2: 2 }, { k1: { i2: "bar", i3: 2 }, k3: 3 }), +); +assertType<{ k1: { i2: string; i3: number }; k2: number; k3: number }>( + foundry.utils.mergeObject( + { k1: { i1: "foo", i3: { j1: 0 } }, k2: 2 }, + { k1: { i2: "bar", i3: 2 }, k3: 3 }, + { recursive: false }, + ), +); +expectTypeOf( + foundry.utils.mergeObject( + { k1: { i1: "foo", i3: { j1: 0 } }, k2: 2 }, + { k1: { i2: "bar", i3: 2 }, k3: 3 }, + { recursive: false }, + ).k1, +).toEqualTypeOf<{ i2: string; i3: number }>(); +assertType<{ + k1: { i1: string; i2: string; i3: { j1: string; j2: number; j3: string } }; + k2: number; + k3: number; +}>( + foundry.utils.mergeObject( + { k1: { i1: "foo", i3: { j1: 1, j2: 2 } }, k2: 2 }, + { k1: { i2: "bar", i3: { j1: "1", j3: "3" } }, k3: 3 }, + ), +); +assertType<{ k1: { i1: string; i3: { j1: string; j2: number } }; k2: number; k3: number }>( + foundry.utils.mergeObject( + { k1: { i1: "foo", i3: { j1: 1, j2: 2 } }, k2: 2 }, + { k1: { i2: "bar", i3: { j1: "1", j3: "3" } }, k3: 3 }, + { insertValues: false }, + ), +); +assertType<{ k1: { i2: string; i3: { j1: string; j3: string } }; k2: number; k3: number }>( + foundry.utils.mergeObject( + { k1: { i1: "foo", i3: { j1: 1, j2: 2 } }, k2: 2 }, + { k1: { i2: "bar", i3: { j1: "1", j3: "3" } }, k3: 3 }, + { recursive: false }, + ), +); + +// Array merging + +assertType( + foundry.utils.mergeObject(FormApplication.defaultOptions, { + classes: ["my", "custom", "css"], + }), +); +assertType<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] })); +assertType<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertKeys: true })); +assertType<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertValues: true })); +assertType<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertKeys: false })); +assertType<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { insertValues: false })); +assertType<{ a: number[] }>(foundry.utils.mergeObject({ a: ["foo"] }, { a: [0] }, { enforceTypes: true })); +assertType(foundry.utils.mergeObject({ a: ["foo"] }, { a: { b: "foo" } }, { enforceTypes: true })); +assertType<{ a: { b: string } }>( + foundry.utils.mergeObject({ a: ["foo"] }, { a: { b: "foo" } }, { enforceTypes: false }), +); +assertType(foundry.utils.mergeObject({ a: { b: "foo" } }, { a: ["foo"] }, { enforceTypes: true })); +assertType<{ a: string[] }>(foundry.utils.mergeObject({ a: { b: "foo" } }, { a: ["foo"] }, { enforceTypes: false })); + +// performDeletions +// v10, `-=` prefixed keys are no longer auto removed +assertType<{ k1: string; k2: string; "-=k1": null }>( + foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }), +); +assertType<{ k1: string; k2: string; "-=k1": null }>( + foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: false }), +); +assertType<{ k2: string; "-=k1": null }>(foundry.utils.mergeObject({ k2: "v2" }, { "-=k1": null })); +assertType<{ k1: string; k2: string; "-=k1": null }>( + foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }), +); + +assertType<{ k2: string }>( + foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), +); + +assertType<{ k1: string; k2: string; "-=k1": null }>( + // @ts-expect-error deletions are performed so `-=k1` shouldn't be kept. + foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), +); + +assertType<{ k2: string; "-=k1": null }>( + // @ts-expect-error deletions are performed so `-=k1` shouldn't be kept. + foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), +); + +assertType<{ k1: string; k2: string }>( + // @ts-expect-error deletions are performed so `k1` should be gone. + foundry.utils.mergeObject({ k1: "v1", k2: "v2" }, { "-=k1": null }, { performDeletions: true }), +); + +assertType<{ k2: string }>(foundry.utils.mergeObject({ k2: "v2" }, { "-=k1": null }, { insertKeys: false })); + +assertType<{ k2: string; "-=k1": null }>( + // @ts-expect-error new keys won't be inserted + foundry.utils.mergeObject({ k2: "v2" }, { "-=k1": null }, { insertKeys: false }), +); + +assertType<{ wrapper: { k2: string } }>( + foundry.utils.mergeObject( + { wrapper: { k1: "v1", k2: "v2" } }, + { wrapper: { "-=k1": null } }, + { recursive: true, performDeletions: true }, + ), +); +assertType<{ wrapper: { k1: string; k2: string; "-=k1": null } }>( + foundry.utils.mergeObject({ wrapper: { k1: "v1", k2: "v2" } }, { wrapper: { "-=k1": null } }, { recursive: true }), +); + +// bonus round +assertType<{ a: number; b: number }>(foundry.utils.mergeObject({ a: 1 }, { b: 2 }, { enforceTypes: true })); + +// @ts-expect-error these objects should be mergeable and not never +assertType(foundry.utils.mergeObject({ a: 1 }, { b: 2 }, { enforceTypes: true })); + +assertType<{ a: { a: number; b: number } }>( + foundry.utils.mergeObject({ a: { a: 1 } }, { a: { b: 2 } }, { enforceTypes: true }), +); + +// @ts-expect-error these objects should be mergeable and not never +assertType(foundry.utils.mergeObject({ a: { a: 1 } }, { b: { a: 2 } }, { enforceTypes: true })); + +assertType<{ a: { a: number }; b: { a: number }; c: number }>( + foundry.utils.mergeObject({ a: { a: 1 }, c: 1 }, { b: { a: 2 }, c: 1 }, { enforceTypes: true }), +); + +assertType( + // @ts-expect-error these objects should be mergeable and not never + foundry.utils.mergeObject({ a: { a: 1 }, c: 1 }, { b: { a: 2 }, c: 1 }, { enforceTypes: true }), +); + +// @ts-expect-error - A number isn't a valid object to merge. +foundry.utils.mergeObject(1, 2); + +// @ts-expect-error - A string isn't a valid object to merge. +foundry.utils.mergeObject("foo", "bar"); diff --git a/tests/foundry/common/utils/http.mjs.test-d.ts b/tests/foundry/common/utils/http.mjs.test-d.ts new file mode 100644 index 000000000..faa9b1c73 --- /dev/null +++ b/tests/foundry/common/utils/http.mjs.test-d.ts @@ -0,0 +1,4 @@ +import { expectTypeOf } from "vitest"; + +expectTypeOf(foundry.utils.fetchWithTimeout("/")).toEqualTypeOf>(); +expectTypeOf(foundry.utils.fetchJsonWithTimeout("/")).toEqualTypeOf>(); diff --git a/tests/foundry/common/utils/semaphore.mjs.test-d.ts b/tests/foundry/common/utils/semaphore.mjs.test-d.ts new file mode 100644 index 000000000..476963199 --- /dev/null +++ b/tests/foundry/common/utils/semaphore.mjs.test-d.ts @@ -0,0 +1,13 @@ +import { expectTypeOf } from "vitest"; +import "../../index"; + +declare const lock: Semaphore; + +expectTypeOf(lock.add(async (s: string) => !s, "test")).toEqualTypeOf>(); +expectTypeOf(lock.add(async () => false)).toEqualTypeOf>(); + +// @ts-expect-error - The callback needs one argument. +lock.add(async (s: string) => !s); + +// @ts-expect-error - The callback doesn't need any arguments. +lock.add(async () => false, ""); diff --git a/tests/foundry/prosemirror/prosemirror.test-d.ts b/tests/foundry/prosemirror/prosemirror.test-d.ts new file mode 100644 index 000000000..2681ddd38 --- /dev/null +++ b/tests/foundry/prosemirror/prosemirror.test-d.ts @@ -0,0 +1,7 @@ +import type { Schema } from "prosemirror-model"; +import type { EditorState } from "prosemirror-state"; +import { expectTypeOf } from "vitest"; + +expectTypeOf(ProseMirror.EditorState).toEqualTypeOf(); +expectTypeOf(ProseMirror.Schema).toEqualTypeOf(); +expectTypeOf(ProseMirror.defaultSchema).toEqualTypeOf(); diff --git a/tests/tsconfig.json b/tests/tsconfig.json new file mode 100644 index 000000000..c811f31db --- /dev/null +++ b/tests/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "module": "esnext" + }, + "include": ["../index.d.ts", "./foundry", "./types", "./custom"] +} diff --git a/tests/types/utils.test-d.ts b/tests/types/utils.test-d.ts new file mode 100644 index 000000000..a833b4774 --- /dev/null +++ b/tests/types/utils.test-d.ts @@ -0,0 +1,100 @@ +import { assertType, expectTypeOf } from "vitest"; +import "../../index"; + +const membersBecomeOptional: DeepPartial<{ a: string }> = {}; +expectTypeOf(membersBecomeOptional).toEqualTypeOf<{ a?: string }>(); + +const nestedMembersBecomeOptional: DeepPartial<{ a: { b: string } }> = { a: {} }; +expectTypeOf(nestedMembersBecomeOptional).toEqualTypeOf<{ a?: { b?: string } }>(); + +const expanded1: Expanded<{ foo: string }> = { foo: "" }; +expectTypeOf(expanded1).toEqualTypeOf<{ foo: string }>(); +const expanded2: Expanded<{ "foo.bar": string }> = { foo: { bar: "" } }; +expectTypeOf(expanded2).toEqualTypeOf<{ foo: { bar: string } }>(); +const expanded3: Expanded<{ "foo.bar": string[] }> = { foo: { bar: [""] } }; +expectTypeOf(expanded3).toEqualTypeOf<{ foo: { bar: string[] } }>(); +const expanded4: Expanded<{ foo: { "bar.baz": string } }> = { foo: { bar: { baz: "" } } }; +expectTypeOf(expanded4).toEqualTypeOf<{ foo: { bar: { baz: string } } }>(); +const expanded5: Expanded<{ "foo.bar": string; "baz.qux": string }> = { foo: { bar: "" }, baz: { qux: "" } }; +expectTypeOf(expanded5).toEqualTypeOf<{ foo: { bar: string }; baz: { qux: string } }>(); +const expanded6: Expanded<{ "foo.bar": string; baz: { qux: string } }> = { foo: { bar: "" }, baz: { qux: "" } }; +expectTypeOf(expanded6).toEqualTypeOf<{ foo: { bar: string }; baz: { qux: string } }>(); +const expanded7: Expanded<{ "foo.bar": string | number }> = { foo: { bar: 0 } }; +expectTypeOf(expanded7).toEqualTypeOf<{ foo: { bar: string | number } }>(); +const expanded8: Expanded<{ foo: { bar: string } | { baz: number } }> = { foo: { bar: "" } }; +expectTypeOf(expanded8).toEqualTypeOf<{ foo: { bar: string } | { baz: number } }>(); +const expanded9: Expanded<{ "foo.bar"?: string }> = {}; +expectTypeOf(expanded9).toEqualTypeOf<{ foo?: { bar: string | undefined } }>(); + +declare const titlecaseEmpty: Titlecase<"">; +expectTypeOf(titlecaseEmpty).toEqualTypeOf<"">(); +declare const titlecaseBlank: Titlecase<" ">; +expectTypeOf(titlecaseBlank).toEqualTypeOf<" ">(); +declare const titlecaseNumber: Titlecase<"42">; +expectTypeOf(titlecaseNumber).toEqualTypeOf<"42">(); +declare const titlecaseFromLower: Titlecase<"foobar">; +expectTypeOf(titlecaseFromLower).toEqualTypeOf<"Foobar">(); +declare const titlecaseFromUpper: Titlecase<"FOOBAR">; +expectTypeOf(titlecaseFromUpper).toEqualTypeOf<"Foobar">(); +declare const titlecaseWithSpace: Titlecase<"foo bar">; +expectTypeOf(titlecaseWithSpace).toEqualTypeOf<"Foo Bar">(); +declare const titlecaseWithSpaces: Titlecase<"foo bar">; +expectTypeOf(titlecaseWithSpaces).toEqualTypeOf<"Foo Bar">(); +declare const titlecaseWithThreeWords: Titlecase<"foo bar baz">; +expectTypeOf(titlecaseWithThreeWords).toEqualTypeOf<"Foo Bar Baz">(); + +const numberMaybePromise: MaybePromise = 0; +expectTypeOf(await numberMaybePromise).toEqualTypeOf(); + +declare const user: User; +expectTypeOf(user.id).toEqualTypeOf(); +expectTypeOf(user.data._id).toEqualTypeOf(); +expectTypeOf(user.data._source._id).toEqualTypeOf(); +expectTypeOf(user.toJSON()._id).toEqualTypeOf(); +expectTypeOf(user.data.toJSON()._id).toEqualTypeOf(); +expectTypeOf(user.toObject()._id).toEqualTypeOf(); +expectTypeOf(user.data.toObject()._id).toEqualTypeOf(); +expectTypeOf(user.toObject(false)._id).toEqualTypeOf(); +expectTypeOf(user.data.toObject(false)._id).toEqualTypeOf(); +expectTypeOf(user.clone()).toEqualTypeOf>(); + +declare const storedUser: StoredDocument; +expectTypeOf(storedUser.id).toEqualTypeOf(); +expectTypeOf(storedUser.data._id).toEqualTypeOf(); +expectTypeOf(storedUser.data._source._id).toEqualTypeOf(); +expectTypeOf(storedUser.toJSON()._id).toEqualTypeOf(); +expectTypeOf(storedUser.data.toJSON()._id).toEqualTypeOf(); +expectTypeOf(storedUser.toObject()._id).toEqualTypeOf(); +expectTypeOf(storedUser.data.toObject()._id).toEqualTypeOf(); +expectTypeOf(storedUser.toObject(false)._id).toEqualTypeOf(); +expectTypeOf(storedUser.data.toObject(false)._id).toEqualTypeOf(); +expectTypeOf(storedUser.clone()).toEqualTypeOf>(); + +declare const actor: StoredDocument; +expectTypeOf(actor.id).toEqualTypeOf(); +expectTypeOf(actor.data._id).toEqualTypeOf(); +expectTypeOf(actor.data._source._id).toEqualTypeOf(); +expectTypeOf(actor.toJSON()._id).toEqualTypeOf(); +expectTypeOf(actor.data.toJSON()._id).toEqualTypeOf(); +expectTypeOf(actor.toObject()._id).toEqualTypeOf(); +expectTypeOf(actor.data.toObject()._id).toEqualTypeOf(); +expectTypeOf(actor.toObject(false)._id).toEqualTypeOf(); +expectTypeOf(actor.data.toObject(false)._id).toEqualTypeOf(); +expectTypeOf(actor.clone()).toEqualTypeOf>(); + +if (actor.data.type === "character") { + expectTypeOf(actor.data.data.health).toEqualTypeOf(); + expectTypeOf(actor.data.data.movement).toEqualTypeOf(); +} else { + expectTypeOf(actor.data.data.faction).toEqualTypeOf(); + expectTypeOf(actor.data.data.challenge).toEqualTypeOf(); + expectTypeOf(actor.data.data.damage).toEqualTypeOf(); +} + +// we need to test with `assertType` because the types are not considered equal, even though they are structurally the same +type A = { foo?: string; bar?: number; baz: boolean }; +type B = { foo: string; bar?: number; baz: boolean }; +declare const someVariable: RequiredProps; +declare const someOtherVariable: B; +assertType(someVariable); +assertType>(someOtherVariable); diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json new file mode 100644 index 000000000..ab3c206a0 --- /dev/null +++ b/tsconfig.eslint.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "include": ["**/*.ts", "**/*.js"] +} diff --git a/vitest.config.js b/vitest.config.js new file mode 100644 index 000000000..455e665a2 --- /dev/null +++ b/vitest.config.js @@ -0,0 +1,11 @@ +// @ts-check + +import { defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + typecheck: { + tsconfig: "./tests/tsconfig.json", + }, + }, +});