chore: enable exactOptionalPropertyTypes support#9050
Open
YevheniiKotyrlo wants to merge 1 commit intosoftware-mansion:mainfrom
Open
chore: enable exactOptionalPropertyTypes support#9050YevheniiKotyrlo wants to merge 1 commit intosoftware-mansion:mainfrom
exactOptionalPropertyTypes support#9050YevheniiKotyrlo wants to merge 1 commit intosoftware-mansion:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR enables TypeScript's
exactOptionalPropertyTypesflag inreact-native-reanimatedand fixes all resulting type errors across 19 files.exactOptionalPropertyTypesis a strict TypeScript flag (not included instrict: true) that distinguishes between "property is missing" and "property is explicitlyundefined". When enabled,prop?: Tmeans the property can be omitted but cannot be set toundefined— the fix isprop?: 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:
Core type declarations (
commonTypes.ts,Colors.ts,mappers.ts) — Added| undefinedto optional properties inAnimationObject,LayoutAnimation,AnimatedKeyboardOptions,LabColor,RgbColor, etc.Style processing generics (
common/style/types.ts,propsBuilder.ts,registry.ts) — UsedExclude<Required<P>[K], undefined>to extract the non-undefined type from optional properties before passing toPropsBuilderPropertyConfig<T>AnimatedComponent class hierarchies (
createAnimatedComponent/,css/component/) — Updated class property types andViewInfointerfaces, added type narrowing in_getViewInfo()Layout animation builders (
BaseAnimationBuilder.ts,Keyframe.ts) — Added| undefinedto builder class properties (durationV,delayV,callbackV) andKeyframePoint.easingAll 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 fromreact-native-workletsmodule resolution remain unchanged)yarn workspace react-native-reanimated type:check:src:web— same as native