From 571d8b29673e474ce7b84a9257aee3c00ccf4413 Mon Sep 17 00:00:00 2001 From: Trezy Date: Tue, 28 May 2024 17:02:28 -0500 Subject: [PATCH] fix: fix type errors --- .gitignore | 1 + types/index.d.ts => lib/global.ts | 0 lib/helpers/appendChild.js | 5 +++-- lib/helpers/createInstance.js | 5 ++--- lib/helpers/removeChild.js | 7 ++++--- lib/hooks/useAsset.js | 6 ++++-- lib/render.js | 3 ++- tsconfig.json | 12 ++++++++---- 8 files changed, 24 insertions(+), 15 deletions(-) rename types/index.d.ts => lib/global.ts (100%) diff --git a/.gitignore b/.gitignore index 0abf542c..c3a1243c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ .idea node_modules/ **/dist/ +types/ packages/*/stats.html .eslintcache .DS_Store diff --git a/types/index.d.ts b/lib/global.ts similarity index 100% rename from types/index.d.ts rename to lib/global.ts diff --git a/lib/helpers/appendChild.js b/lib/helpers/appendChild.js index da1c231d..8207365e 100644 --- a/lib/helpers/appendChild.js +++ b/lib/helpers/appendChild.js @@ -1,10 +1,11 @@ /** @typedef {import('pixi.js').Container} Container */ +/** @typedef {import('../types/HostContainer.js').HostContainer} HostContainer */ /** * Adds elements to our scene and attaches geometry and material to meshes. * - * @param {Container} parentInstance - * @param {Container} child + * @param {HostContainer & Container} parentInstance + * @param {HostContainer & Container} child */ export function appendChild(parentInstance, child) { diff --git a/lib/helpers/createInstance.js b/lib/helpers/createInstance.js index aa9a11ff..0d039e81 100644 --- a/lib/helpers/createInstance.js +++ b/lib/helpers/createInstance.js @@ -2,8 +2,7 @@ import * as PIXI from 'pixi.js'; import { applyProps } from './applyProps.js'; import { convertStringToPascalCase } from './convertStringToPascalCase.js'; -/** @typedef {import('../../types/index.js').PixiElements} PixiElements */ -/** @typedef {import('../../types/index.js').PixiElementsImpl} PixiElementsImpl */ +/** @typedef {import('../types/PixiElements.js').PixiElements} PixiElements */ /** * @param {keyof PixiElements} type @@ -18,7 +17,7 @@ export function createInstance(type, props) const name = convertStringToPascalCase(type); // Get class from Pixi.js namespace - const TARGET = /** @type {PixiElementsImpl} */ PIXI[name]; + const TARGET = /** @type {new (...args: any[]) => any} */ (PIXI[name]); let instance; diff --git a/lib/helpers/removeChild.js b/lib/helpers/removeChild.js index 4406c098..3e18cd1f 100644 --- a/lib/helpers/removeChild.js +++ b/lib/helpers/removeChild.js @@ -1,12 +1,13 @@ /** @typedef {import('pixi.js').Container} Container */ +/** @typedef {import('../types/HostContainer.js').HostContainer} HostContainer */ /** * Removes elements from our scene and disposes of them. * - * @param {Container} _parentInstance Unused. - * @param {Container} child The child to be removed. + * @param {HostContainer & Container} _container Unused. + * @param {HostContainer & Container} child The child to be removed. */ -export function removeChild(_parentInstance, child) +export function removeChild(_container, child) { if (!child) { diff --git a/lib/hooks/useAsset.js b/lib/hooks/useAsset.js index df065646..47af350d 100644 --- a/lib/hooks/useAsset.js +++ b/lib/hooks/useAsset.js @@ -15,7 +15,7 @@ import { * * @param {UnresolvedAsset} options Asset options. * @param {ProgressCallback} [onProgress] A function to be called when the asset loader reports loading progress. - * @returns {Texture} A hash of textures, keyed by their URLs. + * @returns {null | Texture} A hash of textures, keyed by their URLs. This will be `null` until the assets are loaded. */ export function useAsset(options, onProgress) { @@ -34,9 +34,11 @@ export function useAsset(options, onProgress) { setIsLoading(true); + const assetKey = /** @type {string} */ (options.alias ?? options.src); + Assets.add(options); Assets - .load(options.alias ?? options.src, onProgress) + .load(assetKey, onProgress) .then((texture) => { setTexture(texture); diff --git a/lib/render.js b/lib/render.js index 15145e7b..1479edf6 100644 --- a/lib/render.js +++ b/lib/render.js @@ -17,7 +17,7 @@ const roots = new Map(); * This renders an element to a canvas, creates a renderer, scene, etc. * * @param {import('react').ReactNode} component The component to be rendered. - * @param {Element | HTMLCanvasElement} target The target element into which the Pixi application will be rendered. Can be any element, but if a is passed the application will be rendered to it directly. + * @param {HTMLElement | HTMLCanvasElement} target The target element into which the Pixi application will be rendered. Can be any element, but if a is passed the application will be rendered to it directly. * @param {object} [props] * @param {object} [props.size] * @param {number} props.size.height @@ -63,6 +63,7 @@ export function render( // Initiate root if (!root) { + /** @type {Partial} */ const applicationProps = {}; if (canvas) diff --git a/tsconfig.json b/tsconfig.json index 636033fb..a4a61395 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -3,8 +3,13 @@ "allowJs": true, "allowSyntheticDefaultImports": true, "checkJs": true, + "declaration": true, + "declarationDir": "./types", + "emitDeclarationOnly": true, "esModuleInterop": true, + "jsx": "react-jsx", "lib": [ + "DOM", "ESNext" ], "module": "commonjs", @@ -12,17 +17,16 @@ "noUnusedLocals": true, "noUnusedParameters": true, "pretty": true, + "skipLibCheck": true, "sourceMap": true, "strict": true, "target": "ESNext", "baseUrl": "./" }, - "files": [ - "node_modules/jest-extended/types/index.d.ts" - ], "exclude": [ "dist", - "node_modules" + "node_modules", + "types" ], "ts-node": { "files": true,