diff --git a/.eslintrc b/.eslintrc index 287140b53b..40b49f797f 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,6 +19,9 @@ "rules": { "@typescript-eslint/no-unused-vars": "warn", "@typescript-eslint/type-annotation-spacing": "error", + "@typescript-eslint/consistent-type-definitions": ["error", "interface"], + "@typescript-eslint/explicit-module-boundary-types": "warn", + "react/jsx-pascal-case": "error", "react-compiler/react-compiler": "warn", diff --git a/packages/framer-motion/src/motion/types.ts b/packages/framer-motion/src/motion/types.ts index f1c7cda92c..c1b10c9806 100644 --- a/packages/framer-motion/src/motion/types.ts +++ b/packages/framer-motion/src/motion/types.ts @@ -26,29 +26,31 @@ import { ViewportProps } from "./features/viewport/types" */ export type VariantLabels = string | string[] +type stringOrNumber = string | number + export interface TransformProperties { - x?: string | number - y?: string | number - z?: string | number - translateX?: string | number - translateY?: string | number - translateZ?: string | number - rotate?: string | number - rotateX?: string | number - rotateY?: string | number - rotateZ?: string | number - scale?: string | number - scaleX?: string | number - scaleY?: string | number - scaleZ?: string | number - skew?: string | number - skewX?: string | number - skewY?: string | number - originX?: string | number - originY?: string | number - originZ?: string | number - perspective?: string | number - transformPerspective?: string | number + x?: stringOrNumber + y?: stringOrNumber + z?: stringOrNumber + translateX?: stringOrNumber + translateY?: stringOrNumber + translateZ?: stringOrNumber + rotate?: stringOrNumber + rotateX?: stringOrNumber + rotateY?: stringOrNumber + rotateZ?: stringOrNumber + scale?: stringOrNumber + scaleX?: stringOrNumber + scaleY?: stringOrNumber + scaleZ?: stringOrNumber + skew?: stringOrNumber + skewX?: stringOrNumber + skewY?: stringOrNumber + originX?: stringOrNumber + originY?: stringOrNumber + originZ?: stringOrNumber + perspective?: stringOrNumber + transformPerspective?: stringOrNumber } /** @@ -65,19 +67,24 @@ export interface CustomStyles { * Framer Library custom prop types. These are not actually supported in Motion - preferably * we'd have a way of external consumers injecting supported styles into this library. */ - size?: string | number - radius?: string | number + size?: stringOrNumber + radius?: stringOrNumber shadow?: string image?: string } -export type MakeMotion = MakeCustomValueType<{ - [K in keyof T]: - | T[K] - | MotionValue - | MotionValue - | MotionValue // A permissive type for Custom value types -}> +type MotionValueString = MotionValue +type MotionValueNumber = MotionValue +type MotionValueAny = MotionValue +type AMotionValue = MotionValueNumber | MotionValueString | MotionValueAny // any creates a permissive type for Custom value types + +type MotionValueHelper = T | AMotionValue +type MakeMotionHelper = { + [K in keyof T]: MotionValueHelper +} + +type MakeCustomValueTypeHelper = MakeMotionHelper +export type MakeMotion = MakeCustomValueTypeHelper export type MotionCSS = MakeMotion< Omit @@ -88,25 +95,27 @@ export type MotionCSS = MakeMotion< */ export type MotionTransform = MakeMotion +type MotionCSSVariablesHelper = MotionValueNumber | MotionValueString | stringOrNumber + /** * TODO: Currently unused, would like to reimplement with the ability * to still accept React.CSSProperties. */ -export type MotionCSSVariables = { - [key: `--${string}`]: - | MotionValue - | MotionValue - | string - | number +export interface MotionCSSVariables { + [key: `--${string}`]: MotionCSSVariablesHelper } +type CustomStylesValueType = MakeCustomValueType +type MotionSVGProps = MakeMotion + /** * @public */ -export type MotionStyle = MotionCSS & - MotionTransform & - MakeMotion & - MakeCustomValueType +export interface MotionStyle + extends MotionCSS, + MotionTransform, + MotionSVGProps, + CustomStylesValueType {} export type OnUpdate = (v: Target) => void @@ -261,8 +270,10 @@ export interface MotionAdvancedProps { ignoreStrict?: boolean } -type ExternalMotionValues = { - [key: string]: MotionValue | MotionValue +type MotionStringOrNumber = MotionValueNumber | MotionValueString + +interface ExternalMotionValues { + [key: string]: MotionStringOrNumber } /** @@ -325,7 +336,7 @@ export interface MotionProps generatedTransform: string ): string - children?: React.ReactNode | MotionValue | MotionValue + children?: React.ReactNode | MotionStringOrNumber "data-framer-appear-id"?: string } diff --git a/packages/framer-motion/src/render/html/types.ts b/packages/framer-motion/src/render/html/types.ts index 4ac2dc53a0..48dca3a6eb 100644 --- a/packages/framer-motion/src/render/html/types.ts +++ b/packages/framer-motion/src/render/html/types.ts @@ -35,12 +35,16 @@ export interface HTMLRenderState { vars: ResolvedValues } +type PropsWithRefAttributes = PropsWithoutRef

& RefAttributes +interface ReactTypeofSymbol { + readonly $$typeof: symbol +} +type ForwardRefFn = (props: PropsWithRefAttributes) => JSX.Element + /** * @public */ -export type ForwardRefComponent = { readonly $$typeof: symbol } & (( - props: PropsWithoutRef

& RefAttributes -) => JSX.Element) +export type ForwardRefComponent = ForwardRefFn & ReactTypeofSymbol type AttributesWithoutMotionProps = { [K in Exclude]?: Attributes[K] diff --git a/packages/framer-motion/src/render/types.ts b/packages/framer-motion/src/render/types.ts index 340344c200..8a37e57bef 100644 --- a/packages/framer-motion/src/render/types.ts +++ b/packages/framer-motion/src/render/types.ts @@ -7,7 +7,7 @@ import { PresenceContextProps } from "../context/PresenceContext" import { MotionProps } from "../motion/types" import { AnimationDefinition } from "../animation/types" -export type GenericValues = { +export interface GenericValues { [key: string]: string | number } @@ -26,7 +26,7 @@ export type ScrapeMotionValuesFromProps = ( export type UseRenderState = () => RenderState -export type VisualElementOptions = { +export interface VisualElementOptions { visualState: VisualState parent?: VisualElement variantParent?: VisualElement diff --git a/packages/framer-motion/src/types.ts b/packages/framer-motion/src/types.ts index 53b97284e0..c0d2f3b7e6 100644 --- a/packages/framer-motion/src/types.ts +++ b/packages/framer-motion/src/types.ts @@ -9,24 +9,30 @@ import { VariableKeyframesDefinition } from "./animation/types" export type GenericKeyframesTarget = V[] | Array +type stringOrNumber = string | number +type GenericKeyframesTargetNumber = GenericKeyframesTarget +type GenericKeyframesTargetString = GenericKeyframesTarget + /** * @public */ export type ResolvedKeyframesTarget = - | GenericKeyframesTarget - | GenericKeyframesTarget + | GenericKeyframesTargetNumber + | GenericKeyframesTargetString + +type KeyframesTargetCustomValueType = GenericKeyframesTarget /** * @public */ export type KeyframesTarget = | ResolvedKeyframesTarget - | GenericKeyframesTarget + | KeyframesTargetCustomValueType /** * @public */ -export type ResolvedSingleTarget = string | number +export type ResolvedSingleTarget = stringOrNumber /** * @public */ @@ -43,7 +49,9 @@ export type ValueTarget = SingleTarget | KeyframesTarget /** * @public */ -export type Props = { [key: string]: any } +export interface Props { + [key: string]: any +} /** * Options for orchestrating the timing of animations. @@ -394,12 +402,12 @@ export interface Tween extends Repeat { * * @public */ - from?: number | string + from?: stringOrNumber /** * @internal */ - to?: number | string | ValueTarget + to?: stringOrNumber | ValueTarget /** * @internal @@ -581,12 +589,12 @@ export interface Spring extends Repeat { * * @public */ - from?: number | string + from?: stringOrNumber /** * @internal */ - to?: number | string | ValueTarget + to?: stringOrNumber | ValueTarget /** * The initial velocity of the spring. By default this is the current velocity of the component. @@ -783,7 +791,7 @@ export interface Inertia { * * @public */ - from?: number | string + from?: stringOrNumber /** * The initial velocity of the animation. @@ -897,12 +905,12 @@ export interface Keyframes { /** * @internal */ - from?: number | string + from?: stringOrNumber /** * @internal */ - to?: number | string | ValueTarget + to?: stringOrNumber | ValueTarget /** * @internal @@ -929,7 +937,7 @@ export interface None { /** * @internal */ - from?: number | string + from?: stringOrNumber /** * @internal @@ -950,7 +958,7 @@ export type PopmotionTransitionProps = Tween | Spring | Keyframes | Inertia /** * @public */ -export type PermissiveTransitionDefinition = { +export interface PermissiveTransitionDefinition { [key: string]: any } @@ -970,14 +978,16 @@ export type TransitionMap = Orchestration & [key: string]: TransitionDefinition } +interface TransitionTypeStaticallyKnown extends Orchestration, Repeat {} + /** * Transition props * * @public */ export type Transition = - | (Orchestration & Repeat & TransitionDefinition) - | (Orchestration & Repeat & TransitionMap) + | (TransitionTypeStaticallyKnown & TransitionDefinition) + | (TransitionTypeStaticallyKnown & TransitionMap) export type Omit = Pick> type CSSPropertiesWithoutTransitionOrSingleTransforms = Omit< @@ -985,35 +995,43 @@ type CSSPropertiesWithoutTransitionOrSingleTransforms = Omit< "transition" | "rotate" | "scale" | "perspective" > -type SVGTransformAttributes = { +interface SVGTransformAttributes { attrX?: number attrY?: number attrScale?: number } +type SVGElementAttributes = SVGAttributes + type TargetProperties = CSSPropertiesWithoutTransitionOrSingleTransforms & - SVGAttributes & + SVGElementAttributes & SVGTransformAttributes & TransformProperties & CustomStyles & SVGPathProperties & VariableKeyframesDefinition +type MakeCustomValueTypeHelper = T | CustomValueType + /** * @public */ -export type MakeCustomValueType = { [K in keyof T]: T[K] | CustomValueType } +export type MakeCustomValueType = { + [K in keyof T]: MakeCustomValueTypeHelper +} /** * @public */ export type Target = MakeCustomValueType +type MakeKeyframesHelper = T | T[] | [null, ...T[]] + /** * @public */ export type MakeKeyframes = { - [K in keyof T]: T[K] | T[K][] | [null, ...T[K][]] + [K in keyof T]: MakeKeyframesHelper } /** @@ -1041,7 +1059,7 @@ export type TargetWithKeyframes = MakeKeyframes * * @public */ -export type TargetAndTransition = TargetWithKeyframes & { +export interface TargetAndTransition extends TargetWithKeyframes { transition?: Transition transitionEnd?: Target } @@ -1060,7 +1078,7 @@ export type Variant = TargetAndTransition | TargetResolver /** * @public */ -export type Variants = { +export interface Variants { [key: string]: Variant } @@ -1068,6 +1086,6 @@ export type Variants = { * @public */ export interface CustomValueType { - mix: (from: any, to: any) => (p: number) => number | string - toValue: () => number | string + mix: (from: any, to: any) => (p: number) => stringOrNumber + toValue: () => stringOrNumber }