Skip to content

Commit

Permalink
fix: fix type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed May 28, 2024
1 parent 0df7b86 commit 571d8b2
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.idea
node_modules/
**/dist/
types/
packages/*/stats.html
.eslintcache
.DS_Store
File renamed without changes.
5 changes: 3 additions & 2 deletions lib/helpers/appendChild.js
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
5 changes: 2 additions & 3 deletions lib/helpers/createInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
7 changes: 4 additions & 3 deletions lib/helpers/removeChild.js
Original file line number Diff line number Diff line change
@@ -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)
{
Expand Down
6 changes: 4 additions & 2 deletions lib/hooks/useAsset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <canvas> 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 <canvas> is passed the application will be rendered to it directly.
* @param {object} [props]
* @param {object} [props.size]
* @param {number} props.size.height
Expand Down Expand Up @@ -63,6 +63,7 @@ export function render(
// Initiate root
if (!root)
{
/** @type {Partial<import('pixi.js').ApplicationOptions>} */
const applicationProps = {};

if (canvas)
Expand Down
12 changes: 8 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,30 @@
"allowJs": true,
"allowSyntheticDefaultImports": true,
"checkJs": true,
"declaration": true,
"declarationDir": "./types",
"emitDeclarationOnly": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"lib": [
"DOM",
"ESNext"
],
"module": "commonjs",
"moduleResolution": "node",
"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,
Expand Down

0 comments on commit 571d8b2

Please sign in to comment.