Skip to content

Commit

Permalink
convert type defs to proper Typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
trezy committed Jul 4, 2024
1 parent a88fe5f commit 89cdf11
Show file tree
Hide file tree
Showing 64 changed files with 224 additions and 259 deletions.
4 changes: 2 additions & 2 deletions src/components/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ import { useIsomorphicLayoutEffect } from '../hooks/useIsomorphicLayoutEffect.js

/**
* @template T
* @typedef {import('../typedefs/OmitChildren.js').OmitChildren<T>} OmitChildren
* @typedef {import('../typedefs/OmitChildren.ts').OmitChildren<T>} OmitChildren
*/

/** @typedef {import('../typedefs/Root.js').Root} Root */
/** @typedef {import('../typedefs/Root.ts').Root} Root */

/**
* @template T
Expand Down
2 changes: 1 addition & 1 deletion src/components/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { createContext } from 'react';
* @typedef {import('react').Context<T>} Context
*/

/** @typedef {import('../typedefs/InternalState.js').InternalState} InternalState */
/** @typedef {import('../typedefs/InternalState.ts').InternalState} InternalState */

export const Context = /** @type {Context<InternalState | null>} */ (createContext(null));

Expand Down
4 changes: 2 additions & 2 deletions src/core/createRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { roots } from './roots.js';

/** @typedef {import('pixi.js').ApplicationOptions} ApplicationOptions */

/** @typedef {import('../typedefs/InternalState.js').InternalState} InternalState */
/** @typedef {import('../typedefs/Root.js').Root} Root */
/** @typedef {import('../typedefs/InternalState.ts').InternalState} InternalState */
/** @typedef {import('../typedefs/Root.ts').Root} Root */

/**
* Creates a new root for a Pixi React app.
Expand Down
4 changes: 2 additions & 2 deletions src/core/reconciler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import { removeChild } from '../helpers/removeChild.js';
import { resetAfterCommit } from '../helpers/resetAfterCommit.js';
import { shouldSetTextContent } from '../helpers/shouldSetTextContent.js';

/** @typedef {import('../typedefs/HostConfig.js').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/HostConfig.ts').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */

/**
* @type {Reconciler.HostConfig<
Expand Down
2 changes: 1 addition & 1 deletion src/core/roots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* We store roots here since we can render to multiple canvases
*
* @type {Map<HTMLElement, import('../typedefs/Root.js').Root>}
* @type {Map<HTMLElement, import('../typedefs/Root.ts').Root>}
*/
export const roots = new Map();
6 changes: 3 additions & 3 deletions src/global.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { NamespacedPixiElementsImpl } from './typedefs/NamespacedPixiElementsImpl';
import type { PixiElementsImpl } from './typedefs/PixiElementsImpl';
import type { NamespacedPixiElementsImpl } from './typedefs/NamespacedPixiElementsImpl.ts';
import type { PixiElementsImpl } from './typedefs/PixiElementsImpl.ts';

declare global
{
// eslint-disable-next-line @typescript-eslint/no-namespace
namespace React.JSX
namespace JSX
{
interface IntrinsicElements extends PixiElementsImpl, NamespacedPixiElementsImpl {}
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/appendChild.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from './log.js';

/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */

/**
* Adds elements to our application.
Expand Down
21 changes: 16 additions & 5 deletions src/helpers/applyProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { log } from './log.js';
/** @typedef {import('pixi.js').FederatedPointerEvent} FederatedPointerEvent */
/** @typedef {import('pixi.js').FederatedWheelEvent} FederatedWheelEvent */

/** @typedef {import('../typedefs/DiffSet.js').DiffSet} DiffSet */
/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/InstanceProps.js').InstanceProps} InstanceProps */
/** @typedef {import('../typedefs/MaybeInstance.js').MaybeInstance} MaybeInstance */
/** @typedef {import('../typedefs/DiffSet.ts').DiffSet} DiffSet */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */
/** @typedef {import('../typedefs/InstanceProps.ts').InstanceProps} InstanceProps */
/** @typedef {import('../typedefs/MaybeInstance.ts').MaybeInstance} MaybeInstance */

const DEFAULT = '__default';
const DEFAULTS_CONTAINERS = new Map();
Expand All @@ -40,7 +40,18 @@ export function applyProps(instance, data)
} = instance;

/** @type {DiffSet} */
const { changes } = /** @type {*} */ (isDiffSet(data) ? data : diffProps(data, instanceProps));
let typedData;

if (isDiffSet(data))
{
typedData = /** @type {DiffSet} */ (data);
}
else
{
typedData = diffProps(/** @type {InstanceProps} */ (data), instanceProps);
}

const { changes } = typedData;

let changeIndex = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/catalogue.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */

/**
* @type {{
Expand Down
8 changes: 4 additions & 4 deletions src/helpers/commitUpdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { applyProps } from '../helpers/applyProps.js';
import { log } from '../helpers/log.js';
import { switchInstance } from './switchInstance.js';

/** @typedef {import('../typedefs/DiffSet.js').DiffSet} DiffSet */
/** @typedef {import('../typedefs/HostConfig.js').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/InstanceProps.js').InstanceProps} InstanceProps */
/** @typedef {import('../typedefs/DiffSet.ts').DiffSet} DiffSet */
/** @typedef {import('../typedefs/HostConfig.ts').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */
/** @typedef {import('../typedefs/InstanceProps.ts').InstanceProps} InstanceProps */

/**
* @param {Instance} instance The instance to mutate.
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/createInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { gentleCloneProps } from './gentleCloneProps.js';
import { log } from './log.js';
import { prepareInstance } from './prepareInstance.js';

/** @typedef {import('../typedefs/HostConfig.js').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/InstanceProps.js').InstanceProps} InstanceProps */
/** @typedef {import('../typedefs/HostConfig.ts').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */
/** @typedef {import('../typedefs/InstanceProps.ts').InstanceProps} InstanceProps */

/**
* @param {HostConfig['type']} type
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/createTextInstance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from './log.js';

/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */

/**
* text: string, rootContainer: Instance, hostContext: null, internalHandle: any
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/diffProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
import { isEqual } from './compare.js';
import { gentleCloneProps } from './gentleCloneProps.js';

/** @typedef {import('../typedefs/Change.js').Change} Change */
/** @typedef {import('../typedefs/DiffSet.js').DiffSet} DiffSet */
/** @typedef {import('../typedefs/InstanceProps.js').InstanceProps} InstanceProps */
/** @typedef {import('../typedefs/Change.ts').Change} Change */
/** @typedef {import('../typedefs/DiffSet.ts').DiffSet} DiffSet */
/** @typedef {import('../typedefs/InstanceProps.ts').InstanceProps} InstanceProps */

const DEFAULT = '__default';

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/extend.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { catalogue } from './catalogue.js';

/** @typedef {import('../typedefs/AutoFilteredKeys.js').AutoFilteredKeys} AutoFilteredKeys */
/** @typedef {import('../typedefs/AutoFilteredKeys.ts').AutoFilteredKeys} AutoFilteredKeys */

/**
* Expose Pixi.js components for use in JSX.
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getInstanceFromScope.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { log } from './log.js';
/**
* @param {*} _scope Unused.
* @throws {Error} Always throws, because we don't support this.
* @returns {import('../typedefs/Instance.js').Instance}
* @returns {import('../typedefs/Instance.ts').Instance}
*/
export function getInstanceFromScope(_scope)
{
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/insertBefore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { invariant } from './invariant.js';
import { log } from './log.js';

/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */

/**
* @param {Instance} parentInstance
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/isDiffSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
export function isDiffSet(input)
{
const inputAsDiffSet = /** @type {import('../typedefs/DiffSet.js').DiffSet} */ input;
const inputAsDiffSet = /** @type {import('../typedefs/DiffSet.ts').DiffSet} */ input;

if (!inputAsDiffSet)
{
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/prepareInstance.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** @typedef {import('pixi.js').Container} Container */
/** @typedef {import('../typedefs/ContainerElement.js').ContainerElement} ContainerElement */
/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/InstanceState.js').InstanceState} InstanceState */
/** @typedef {import('../typedefs/ContainerElement.ts').ContainerElement} ContainerElement */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */
/** @typedef {import('../typedefs/InstanceState.ts').InstanceState} InstanceState */

/**
* Create the instance with the provided sate and attach the component to it.
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/prepareUpdate.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { diffProps } from './diffProps.js';
import { log } from './log.js';

/** @typedef {import('../typedefs/DiffSet.js').DiffSet} DiffSet */
/** @typedef {import('../typedefs/InstanceProps.js').InstanceProps} InstanceProps */
/** @typedef {import('../typedefs/DiffSet.ts').DiffSet} DiffSet */
/** @typedef {import('../typedefs/InstanceProps.ts').InstanceProps} InstanceProps */

/**
*
* @param {import('../typedefs/Instance.js').Instance} _instance Unused.
* @param {import('../typedefs/Instance.ts').Instance} _instance Unused.
* @param {string} _type Unused.
* @param {InstanceProps} oldProps Old props.
* @param {InstanceProps} newProps New props.
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/removeChild.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from './log.js';

/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */

/**
* Removes elements from our scene and disposes of them.
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/switchInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { appendChild } from './appendChild.js';
import { createInstance } from './createInstance.js';
import { removeChild } from './removeChild.js';

/** @typedef {import('../typedefs/HostConfig.js').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.js').Instance} Instance */
/** @typedef {import('../typedefs/HostConfig.ts').HostConfig} HostConfig */
/** @typedef {import('../typedefs/Instance.ts').Instance} Instance */

/**
* @param {HostConfig['instance']} instance
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useContext } from 'react';
import { Context } from '../components/Context.js';
import { invariant } from '../helpers/invariant';

/** @typedef {import('../typedefs/InternalState.js').InternalState} InternalState */
/** @typedef {import('../typedefs/InternalState.ts').InternalState} InternalState */

export function useApp()
{
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export { useTick } from './hooks/useTick.js';
// If you or someone you know has been hurt by Typescript, or knows how to fix
// this, you may be entitled to benefits. Please call 'tel:555-555-5555' in your
// browser devtools.
export * from './global.ts';
export * from './global.js';
8 changes: 0 additions & 8 deletions src/typedefs/AutoFilteredKeys.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/typedefs/AutoFilteredKeys.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type * as PIXI from 'pixi.js';

type PixiType = typeof PIXI;

export type AutoFilteredKeys = {
[K in keyof PixiType]: PixiType[K] extends new (...args: any) => any ? K : never
}[keyof PixiType];
9 changes: 0 additions & 9 deletions src/typedefs/Change.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/typedefs/Change.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type Change = [
string, // key
unknown, // value
boolean, // isEvent
string[], // keys
];
5 changes: 0 additions & 5 deletions src/typedefs/ConstructorParams.js

This file was deleted.

1 change: 1 addition & 0 deletions src/typedefs/ConstructorParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type ConstructorParams<T extends abstract new (...args: any) => any> = T extends new (...args: infer A) => any ? A[0] : never;
5 changes: 0 additions & 5 deletions src/typedefs/ContainerElement.js

This file was deleted.

4 changes: 4 additions & 0 deletions src/typedefs/ContainerElement.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { Container } from 'pixi.js';
import type { ReactElement } from 'react';

export type ContainerElement = Container & ReactElement;
5 changes: 0 additions & 5 deletions src/typedefs/DiffSet.js

This file was deleted.

6 changes: 6 additions & 0 deletions src/typedefs/DiffSet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { Change } from './Change.ts';

export interface DiffSet
{
changes: Change[],
}
12 changes: 0 additions & 12 deletions src/typedefs/EventHandlers.js

This file was deleted.

10 changes: 10 additions & 0 deletions src/typedefs/EventHandlers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { type ReactToPixiEventPropNames } from '../constants/EventPropNames.js';

import type {
FederatedPointerEvent,
FederatedWheelEvent,
} from 'pixi.js';

export type EventHandlers = {
-readonly [K in keyof typeof ReactToPixiEventPropNames]?: (event: FederatedPointerEvent | FederatedWheelEvent) => void
};
21 changes: 0 additions & 21 deletions src/typedefs/HostConfig.js

This file was deleted.

20 changes: 20 additions & 0 deletions src/typedefs/HostConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Instance } from './Instance.ts';
import type { NamespacedPixiElementsImpl } from './NamespacedPixiElementsImpl.ts';
import type { PixiElementsImpl } from './PixiElementsImpl.ts';

export interface HostConfig
{
type: keyof PixiElementsImpl | keyof NamespacedPixiElementsImpl;
props: Record<string, unknown>;
container: Instance;
instance: Instance;
textInstance: Instance;
suspenseInstance: Instance;
hydratableInstance: never;
publicInstance: Instance;
hostContext: null;
updatePayload: object;
childSet: never;
timeoutHandle: number;
noTimeout: -1;
}
Loading

0 comments on commit 89cdf11

Please sign in to comment.