Conform more of the codebase to strict types (#11162)

This commit is contained in:
Michael Telatynski 2023-06-29 12:17:05 +01:00 committed by GitHub
parent 9c7d935aae
commit 95283d21bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 36 additions and 31 deletions

View file

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import React, { Key, ReactElement, ReactInstance } from "react";
import React, { Key, ReactElement, ReactFragment, ReactInstance, ReactPortal } from "react";
import ReactDom from "react-dom";
interface IChildProps {
@ -33,6 +33,10 @@ interface IProps {
startStyles: React.CSSProperties[];
}
function isReactElement(c: ReactElement | ReactFragment | ReactPortal): c is ReactElement {
return typeof c === "object" && "type" in c;
}
/**
* The NodeAnimator contains components and animates transitions.
* It will only pick up direct changes to properties ('left', currently), and so
@ -72,7 +76,8 @@ export default class NodeAnimator extends React.Component<IProps> {
private updateChildren(newChildren: React.ReactNode): void {
const oldChildren = this.children || {};
this.children = {};
React.Children.toArray(newChildren).forEach((c: ReactElement) => {
React.Children.toArray(newChildren).forEach((c) => {
if (!isReactElement(c)) return;
if (oldChildren[c.key!]) {
const old = oldChildren[c.key!];
const oldNode = ReactDom.findDOMNode(this.nodes[old.key!]);