Skip to content

Commit

Permalink
fix: fix animated components ref types (#36472)
Browse files Browse the repository at this point in the history
Summary:
I found Animated components like `View`, `Text`, `ScrollView`, `Image` ref type inferred as `any` when ref callback used.

![Screen Shot 2023-03-14 at 7 32 53 PM](https://user-images.githubusercontent.com/64301935/224975295-21047dab-7bd1-4023-93d4-a6ee5c47f1e5.png)

this is happening because of `unknown` type is included as union type as below.

![Screen Shot 2023-03-14 at 7 33 01 PM](https://user-images.githubusercontent.com/64301935/224975937-6ee49f7e-55f7-4391-a752-c52c5171ec02.png)

So I excluded `unknown` type inferring via fixing `TAugmentRef` utility type.

Result below!

![Screen Shot 2023-03-14 at 7 33 36 PM](https://user-images.githubusercontent.com/64301935/224976685-da66e5ec-3ef0-41dd-9e1f-2bb8bfcdf598.png)

## Changelog

[GENERAL] [FIXED] - fix animated components ref type inferred `any`

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

Pull Request resolved: #36472

Test Plan: Ran `yarn test-typescript` and `yarn test-typescript-offline` with no errors.

Reviewed By: cipolleschi

Differential Revision: D44055510

Pulled By: dmytrorykun

fbshipit-source-id: 0d380a2c2198c84d586889e912dec5d2304c213a
  • Loading branch information
jeongshin authored and facebook-github-bot committed Mar 16, 2023
1 parent ac5aec3 commit 419b41f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Libraries/Animated/Animated.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@ export namespace Animated {
type NonAnimatedProps = 'key' | 'ref';

type TAugmentRef<T> = T extends React.Ref<infer R>
? React.Ref<R | LegacyRef<R>>
? unknown extends R
? never
: React.Ref<R | LegacyRef<R>>
: never;

export type AnimatedProps<T> = {
Expand Down

0 comments on commit 419b41f

Please sign in to comment.