Skip to content

chore: enable exactOptionalPropertyTypes support#9050

Open
YevheniiKotyrlo wants to merge 1 commit intosoftware-mansion:mainfrom
YevheniiKotyrlo:fix/exact-optional-property-types
Open

chore: enable exactOptionalPropertyTypes support#9050
YevheniiKotyrlo wants to merge 1 commit intosoftware-mansion:mainfrom
YevheniiKotyrlo:fix/exact-optional-property-types

Conversation

@YevheniiKotyrlo
Copy link
Contributor

Summary

This PR enables TypeScript's exactOptionalPropertyTypes flag in react-native-reanimated and fixes all resulting type errors across 19 files.

exactOptionalPropertyTypes is a strict TypeScript flag (not included in strict: true) that distinguishes between "property is missing" and "property is explicitly undefined". When enabled, prop?: T means the property can be omitted but cannot be set to undefined — the fix is prop?: T | undefined.

This matters for downstream projects that enable this flag — without this change, they get type errors when using reanimated APIs. This is currently blocking react-navigation from enabling the flag.

What changed

Four categories of fixes:

  1. Core type declarations (commonTypes.ts, Colors.ts, mappers.ts) — Added | undefined to optional properties in AnimationObject, LayoutAnimation, AnimatedKeyboardOptions, LabColor, RgbColor, etc.

  2. Style processing generics (common/style/types.ts, propsBuilder.ts, registry.ts) — Used Exclude<Required<P>[K], undefined> to extract the non-undefined type from optional properties before passing to PropsBuilderPropertyConfig<T>

  3. AnimatedComponent class hierarchies (createAnimatedComponent/, css/component/) — Updated class property types and ViewInfo interfaces, added type narrowing in _getViewInfo()

  4. Layout animation builders (BaseAnimationBuilder.ts, Keyframe.ts) — Added | undefined to builder class properties (durationV, delayV, callbackV) and KeyframePoint.easing

All changes are type annotations only — zero runtime changes.

Test plan

  • yarn workspace react-native-reanimated type:check:src:native — 0 new errors (58 pre-existing TS2307/TS7017 from react-native-worklets module resolution remain unchanged)
  • yarn workspace react-native-reanimated type:check:src:web — same as native
  • Prettier check on all modified files — pass

Add `| undefined` to optional properties in type declarations, use
Exclude<> for generic type parameters, and add type narrowing guards
to support TypeScript's exactOptionalPropertyTypes flag.

Zero runtime changes — all modifications are type annotations only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant