Skip to content

Commit

Permalink
Update types.
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 7216d928969f77cb4329dec85c55f8edb6f1bfde
  • Loading branch information
cpojer committed Dec 11, 2024
1 parent 4fa2d60 commit c387d4c
Show file tree
Hide file tree
Showing 18 changed files with 31 additions and 26 deletions.
6 changes: 3 additions & 3 deletions docs/content/playground/ClientComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Spinner from '@deities/ui/Spinner.tsx';
import Stack from '@deities/ui/Stack.tsx';
import { Suspense, useEffect, useState } from 'react';
import { ReactElement, Suspense, useEffect, useState } from 'react';

export default function ClientComponent({
module: Module,
}: {
module: () => JSX.Element;
module: () => ReactElement;
}) {
const [element, setElement] = useState<JSX.Element | null>(null);
const [element, setElement] = useState<ReactElement | null>(null);

useEffect(() => {
import('./ClientScope.tsx').then(({ default: ClientScope }) =>
Expand Down
3 changes: 2 additions & 1 deletion docs/content/playground/ClientScope.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ScaleContext } from '@deities/ui/hooks/useScale.tsx';
import { setDefaultPortalContainer } from '@deities/ui/Portal.tsx';
import { css } from '@emotion/css';
import { init as initFbt, IntlVariations } from 'fbt';
import { ReactElement } from 'react';

initializeCSSVariables();

Expand Down Expand Up @@ -68,7 +69,7 @@ if (import.meta.env.DEV) {
import('@deities/hera/ui/fps/Fps.tsx');
}

export default function ClientScope({ children }: { children: JSX.Element }) {
export default function ClientScope({ children }: { children: ReactElement }) {
return (
<ScaleContext>
<HideContext>
Expand Down
4 changes: 2 additions & 2 deletions hera/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { css, cx } from '@emotion/css';
import ImmutableMap from '@nkzw/immutable-map';
import Images from 'athena-crisis:images';
// eslint-disable-next-line @deities/no-lazy-import
import { lazy } from 'react';
import { lazy, ReactElement } from 'react';
import Building from './Building.tsx';
import Decorators from './Decorators.tsx';
import Fog from './Fog.tsx';
Expand Down Expand Up @@ -144,7 +144,7 @@ const MapComponent = ({
<Decorators map={map} paused={paused} tileSize={tileSize} />
{renderEntities && (
<Tick animationConfig={animationConfig} paused={paused}>
{map.reduceEachField<Array<JSX.Element>>((list, vector) => {
{map.reduceEachField<Array<ReactElement>>((list, vector) => {
const animation = animations?.get(vector);
const building = map.buildings.get(vector);
const unit = map.units.get(vector);
Expand Down
5 changes: 3 additions & 2 deletions hera/MapAnimations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ImmutableMap from '@nkzw/immutable-map';
import { AnimatePresence } from 'framer-motion';
import {
ComponentType,
ReactElement,
ReactNode,
useCallback,
useEffect,
Expand Down Expand Up @@ -767,8 +768,8 @@ export function MapAnimations({
skipBanners?: boolean;
state: State;
}) {
const animationsWithTransitions: Array<JSX.Element> = [];
const mainAnimations: Array<JSX.Element> = [];
const animationsWithTransitions: Array<ReactElement> = [];
const mainAnimations: Array<ReactElement> = [];
animations.forEach((animation, position) => {
const { type } = animation;
if (
Expand Down
4 changes: 2 additions & 2 deletions hera/animations/Animation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function Animation({
}, [initialDelay, rate, rumble, rumbleDuration, sound]);

const setRef = useCallback(
async (element: HTMLDivElement) => {
(element: HTMLDivElement) => {
if (!element) {
return;
}
Expand Down Expand Up @@ -107,7 +107,7 @@ export default function Animation({
}
}
};
await scheduleTimer(next, initialDelay);
scheduleTimer(next, initialDelay);
},
[
delay,
Expand Down
4 changes: 2 additions & 2 deletions hera/behavior/AbstractSelectBehavior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Building from '@deities/athena/map/Building.tsx';
import Entity from '@deities/athena/map/Entity.tsx';
import Unit from '@deities/athena/map/Unit.tsx';
import Vector from '@deities/athena/map/Vector.tsx';
import { useCallback } from 'react';
import { ReactElement, useCallback } from 'react';
import { Actions, State, StateLike, StateWithActions } from '../Types.tsx';
import SelectEntity from '../ui/SelectEntity.tsx';
import { resetBehavior, selectFallback } from './Behavior.tsx';
Expand Down Expand Up @@ -76,7 +76,7 @@ export default abstract class AbstractSelectBehavior {
);
}

component = ({ actions, state }: StateWithActions): JSX.Element | null => {
component = ({ actions, state }: StateWithActions): ReactElement | null => {
return (
<SelectEntity
actions={actions}
Expand Down
2 changes: 1 addition & 1 deletion hera/drawer/Drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Drawer({
inset?: number;
mode?: string;
position?: DrawerPosition;
ref?: RefObject<HTMLDivElement>;
ref?: RefObject<HTMLDivElement | null>;
sidebar?: ReactNode;
visible: boolean;
}>) {
Expand Down
7 changes: 5 additions & 2 deletions hera/editor/behavior/EntityBehavior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Building from '@deities/athena/map/Building.tsx';
import Entity, { isBuilding, isUnit } from '@deities/athena/map/Entity.tsx';
import Unit from '@deities/athena/map/Unit.tsx';
import Vector from '@deities/athena/map/Vector.tsx';
import { useCallback } from 'react';
import { ReactElement, useCallback } from 'react';
import AbstractSelectBehavior from '../../behavior/AbstractSelectBehavior.tsx';
import { MenuItemProps } from '../../behavior/Menu.tsx';
import Cursor from '../../Cursor.tsx';
Expand Down Expand Up @@ -148,7 +148,10 @@ export default class EntityBehavior extends AbstractSelectBehavior {
return { building, unit };
}

override component = ({ actions, state }: StateWithActions) => {
override component = ({
actions,
state,
}: StateWithActions): ReactElement | null => {
const { update } = actions;
const {
map,
Expand Down
2 changes: 1 addition & 1 deletion hera/editor/lib/ActionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export default memo(function ActionCard({
onChange?: ActionChangeFn;
playerDetails?: PlayerDetails;
position?: DrawerPosition;
scrollRef: RefObject<HTMLElement> | null;
scrollRef: RefObject<HTMLElement | null> | null;
setMap?: SetMapFunction;
trigger?: EffectTrigger;
user: UserWithUnlocks | null;
Expand Down
2 changes: 1 addition & 1 deletion hera/editor/panels/EffectsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function EffectsPanel({
map: MapData;
position: DrawerPosition;
scenario: Scenario;
scrollRef: RefObject<HTMLElement>;
scrollRef: RefObject<HTMLElement | null>;
setEditorState: SetEditorStateFunction;
setMap: SetMapFunction;
setScenario: (scenario: Scenario) => void;
Expand Down
2 changes: 1 addition & 1 deletion hera/editor/panels/MapEditorControlPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export default function MapEditorControlPanel({
user: UserWithUnlocks;
visible: boolean;
}) {
const ref = useRef(null);
const ref = useRef<HTMLDivElement>(null);
const updateEffect = useCallback(
(effect: Effect) => {
const { effect: currentEffect, trigger } = editor.scenario;
Expand Down
2 changes: 1 addition & 1 deletion hera/hooks/useClientGameAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function useClientGameAction(
onError?: ((error: Error) => void) | null,
mutateAction?: MutateActionResponseFnName | null,
) {
const actionQueue = useRef<Promise<GameActionResponse>>();
const actionQueue = useRef<Promise<GameActionResponse>>(undefined);
return useCallback(
(action: Action): Promise<GameActionResponse> =>
(actionQueue.current = (actionQueue.current || Promise.resolve(null))
Expand Down
4 changes: 2 additions & 2 deletions hera/ui/GameActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ const EndTurnButton = ({
const { currentViewer, lastActionResponse, map, vision } = state;
const [endTurnIsExpanded, setEndTurnIsExpanded] = useState<boolean>(false);
const [cooldown, setCooldown] = useState(false);
const timerRef = useRef<NativeTimeout>();
const highlightTimerRef = useRef<NativeTimeout>();
const timerRef = useRef<NativeTimeout>(null);
const highlightTimerRef = useRef<NativeTimeout>(null);

useEffect(() => {
if (cooldown) {
Expand Down
2 changes: 1 addition & 1 deletion hera/ui/TeamSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ const PlayerIconWithDrag = ({
onLeave,
selected,
}: {
container: RefObject<Element>;
container: RefObject<HTMLElement | null>;
id: PlayerID;
navigate: [Team | undefined, Team | undefined];
onDrag: (id: PlayerID | null, ghost: boolean) => void;
Expand Down
2 changes: 1 addition & 1 deletion ui/MenuButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default memo(function MenuButton({
delay?: boolean;
hide?: boolean;
onClick?: (event: MouseEvent) => void;
ref?: RefObject<HTMLDivElement>;
ref?: RefObject<HTMLDivElement | null>;
style?: MotionStyle;
}) {
return (
Expand Down
2 changes: 1 addition & 1 deletion ui/TagInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function TagInput<T>({
tags: ReadonlyArray<T>;
toValue?: (tag: T) => string;
}) {
const inputRef = useRef<HTMLInputElement>();
const inputRef = useRef<HTMLInputElement>(undefined);
const ignoreList = useMemo(() => new Set(tags.map(toValue)), [tags, toValue]);
return (
<Stack
Expand Down
2 changes: 1 addition & 1 deletion ui/Typeahead.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ export default function Typeahead<T>({
);

const [highlightedIndex, setHighlightedIndex] = useState(-1);
const input = useRef<HTMLInputElement>();
const input = useRef<HTMLInputElement>(undefined);

const resetResults = useCallback(() => {
setResults(emptySuggestions?.length ? emptySuggestions : []);
Expand Down
2 changes: 1 addition & 1 deletion ui/hooks/useScrollIntoView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RefObject, useEffect } from 'react';

export default function useScrollIntoView(
element: RefObject<HTMLElement>,
element: RefObject<HTMLElement | null>,
scrollIntoView: boolean | undefined,
) {
useEffect(() => {
Expand Down

0 comments on commit c387d4c

Please sign in to comment.