Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove react-native-reanimated.d.ts #4519

Merged
merged 59 commits into from
Jun 29, 2023
Merged

Remove react-native-reanimated.d.ts #4519

merged 59 commits into from
Jun 29, 2023

Conversation

tjzel
Copy link
Contributor

@tjzel tjzel commented Jun 1, 2023

Motivation

Since React Native Reanimated started as a pure JavaScript library at some point it was decided to migrate to TypeScript. Code base was complex enough for this task to be difficult and automatically generated type definitions weren't coherent with the API. Therefore a manually written file was required to provide better types for people that use TypeScript. However this created problems on its own as not all of the changes were put into the d.ts file and differences between inferred type and manual type could be very significant. After time we circled back to complete the TypeScript migration and remove this intermediate d.ts file.

Summary

The goal of this PR is to remove react-native-reanimated.d.ts file that had all of our manually written type definitions in favor of automatically generated files stemming from source files. Since this was still a strenuous task we've decided not to fix all the internal types just yet and preserve only the necessary manually written types from the d.ts file. There's quite a lot of type casting due to that but this is planned to be corrected in the future as well.

Fixes: #4616, #4556

Test plan

I've added the following script to our package.json: yarn type:check-api. It compiles source code of our examples with the use of autogenerated type definitions. It was my main tool of performing this migration an was extremely handy.

All of our static check were useful as well - of course linting and type checking the source code.

Since our Examples don't cover all of the cases of our API usage (although I believe they cover a significant part of it) and we've kept as little of the d.ts file as possible it's to be expected for type errors to be reported in the future - but I think it's the better way to do it than to attempt to generate more API use cases by us.

piaskowyk and others added 30 commits September 23, 2022 07:54
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

The `FrameInfo` interface was not being exported out of the package,
although it's present in the old `.d.ts` file, this PR adds the missing
export.
## Description

This PR is part of an ongoing effort to get rid of the `.d.ts` file and
use type definitions generated based on the source code.

## Changes

- Changed `measure` to be a generic function
- Changed `scrollTo` to be a generic function

## Checklist

- [x] Included code example that can be used to test this change
- [x] Updated TS types
- [x] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes

---------

Co-authored-by: Tomasz Żelawski <tomasz.zelawski@swmansion.com>
Co-authored-by: Tomasz Żelawski <40713406+tjzel@users.noreply.github.com>
## Description

This PR is part of an ongoing effort to get rid of `.d.ts` file and use
type definitions generated based on the source files.

## Changes

- Update exported FlatList type to be generic
- Export type and the component under the same name

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes

---------

Co-authored-by: Tomasz Żelawski <40713406+tjzel@users.noreply.github.com>
## Description

This PR is a part of the ongoing effort to get rid of Reanimated's
`.d.ts` file and switch to types generated based on the source code.

## Changes

- Updated types of `useAnimatedGestureHandler` types to be compatible
with the ones present in the `.d.ts`

## Checklist

- [ ] Updated TS types
- [ ] Included code example that can be used to test this change
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes
## Description

This PR is part of an ongoing effort to get rid of the `.d.ts` file and
switch to types generated based on the source code.

## Changes

- Updated `AnimatedStyle` to allow primitives for certain props
- Updated `useAnimatedStyle` to not accept functions returning arrays

## Checklist

- [ ] Included code example that can be used to test this change
- [ ] Updated TS types
- [ ] Added TS types tests
- [ ] Added unit / integration tests
- [ ] Updated documentation
- [ ] Ensured that CI passes
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR is part of an ongoing effort to get rid of `.d.ts` file and use
type definitions generated based on the source files.

In this case, I've changed `AnimatedSensor` to be generic and provide
different sensors depending on what it's parametrized with. This way
it's easy to overload `useAnimatedSensor` and setup the correct typings
depending on what sensor is being created.

---------

Co-authored-by: Tomasz Żelawski <tomasz.zelawski@swmansion.com>
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR is part of an ongoing effort to get rid of `.d.ts` file and use
type definitions generated based on the source files.

The focus of this PR is on the code responsible for building layout
animations. Instead of hard-coded return types in builders, it uses the
implicit `this` argument to infer the type that should be returned.
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

This PR is part of an ongoing effort to get rid of `.d.ts` file and use
type definitions generated based on the source files.

The main focus of this PR is to make `withDelay` and `withRepeat`
generic functions so that they can accept any animation as an argument
instead of only their own type.

## Test plan

<!-- Provide a minimal but complete code snippet that can be used to
test out this change along with instructions how to run it and a
description of the expected behavior. -->
src/createAnimatedComponent.tsx Outdated Show resolved Hide resolved
Copy link
Member

@piaskowyk piaskowyk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
2.
image

app/src/examples/OldMeasureExample.tsx Show resolved Hide resolved
src/createAnimatedComponent.tsx Show resolved Hide resolved
src/reanimated2/NativeMethods.ts Show resolved Hide resolved
src/reanimated2/js-reanimated/index.ts Outdated Show resolved Hide resolved
src/reanimated2/index.ts Outdated Show resolved Hide resolved
src/reanimated2/hook/useAnimatedSensor.ts Show resolved Hide resolved
@tjzel
Copy link
Contributor Author

tjzel commented Jun 29, 2023

@piaskowyk

image 2. image

  1. Error comes from TypeScript inferring an array a bit higher in the code as an array of never. This fixes it:
-  const output = [];
+  const output: JSX.Element[] = [];
  1. Error is caused, from what I understand, imageRef being a inferred as a react-native component instead of being reanimated animated Image counterpart component. (tl;dr - improperly typed example).

I think it's better to fix these changes in separate PR, not to bloat this one more.

@tjzel tjzel added this pull request to the merge queue Jun 29, 2023
Merged via the queue into main with commit 1c255d1 Jun 29, 2023
8 checks passed
@tjzel tjzel deleted the @tjzel/types/remove-dts branch June 29, 2023 13:38
github-merge-queue bot pushed a commit that referenced this pull request Jul 2, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary
`const IS_WEB = isWeb();` was accidentaly moved inside the `'worklet'`
function in this
[PR](#4519)
on `decay.ts`

This PR moves it outside the `'worket'` function.

Fixes:
#4656

Co-authored-by: Efstathios Ntonas <stathis@hikiapp.com>
Latropos pushed a commit that referenced this pull request Jul 3, 2023
## Motivation

Since React Native Reanimated started as a pure JavaScript library at
some point it was decided to migrate to TypeScript. Code base was
complex enough for this task to be difficult and automatically generated
type definitions weren't coherent with the API. Therefore a manually
written file was required to provide better types for people that use
TypeScript. However this created problems on its own as not all of the
changes were put into the `d.ts` file and differences between inferred
type and manual type could be very significant. After time we circled
back to complete the TypeScript migration and remove this intermediate
`d.ts` file.

## Summary

The goal of this PR is to remove `react-native-reanimated.d.ts` file
that had all of our manually written type definitions in favor of
automatically generated files stemming from source files. Since this was
still a strenuous task we've decided not to fix all the internal types
just yet and preserve only the necessary manually written types from the
`d.ts` file. There's quite a lot of type casting due to that but this is
planned to be corrected in the future as well.

Fixes: #4616, #4556 

## Test plan

I've added the following script to our `package.json`: `yarn
type:check-api`. It compiles source code of our examples with the use of
autogenerated type definitions. It was my main tool of performing this
migration an was extremely handy.

All of our static check were useful as well - of course linting and type
checking the source code.

Since our Examples don't cover all of the cases of our API usage
(although I believe they cover a significant part of it) and we've kept
as little of the `d.ts` file as possible it's to be expected for type
errors to be reported in the future - but I think it's the better way to
do it than to attempt to generate more API use cases by us.

---------

Co-authored-by: Krzysztof Piaskowy <krzysztof.piaskowy@swmansion.com>
Co-authored-by: Karol Wąsowski <karol.wasowski@swmansion.com>
Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
Co-authored-by: Jakub Piasecki <jakub.piasecki@swmansion.com>
Co-authored-by: Jakub Piasecki <jakubpiasecki67@gmail.com>
Latropos pushed a commit that referenced this pull request Jul 3, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary
`const IS_WEB = isWeb();` was accidentaly moved inside the `'worklet'`
function in this
[PR](#4519)
on `decay.ts`

This PR moves it outside the `'worket'` function.

Fixes:
#4656

Co-authored-by: Efstathios Ntonas <stathis@hikiapp.com>
github-merge-queue bot pushed a commit that referenced this pull request Jul 5, 2023
## Summary

Added as discussed in #4519. All changes in file except for `.eslint.rc`
were made automatically by `eslint --fix` and `yarn format`.
Latropos pushed a commit that referenced this pull request Jul 13, 2023
## Summary

Added as discussed in #4519. All changes in file except for `.eslint.rc`
were made automatically by `eslint --fix` and `yarn format`.
github-merge-queue bot pushed a commit that referenced this pull request Aug 4, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

During removal of `react-native-reanimated.d.ts` in #4519 I didn't
consider that some types were exported only in the aforementioned file,
e.g. `WithSpringConfig`. Therefore when we released `3.4.0` those types
disappear from public API. This PR restores lacking types from `.d.ts` -
but only the relevant ones, without Reanimated1 API.

## Types restored

### namespace Animated

- Extrapolate
- DerivedValue
- Adaptable
- TransformStyleTypes
- AdaptTransforms
- AnimatedTransform
- AnimateStyle
- StylesOrDefault
- AnimateProps
- EasingFunction
- addWhitelistedNativeProps
- addWhitelistedUIProps
- AnimatedScrollViewProps
- FlatListPropsWithLayout

### react-native-reanimated

- Adaptable
- AdaptTransforms
- AnimatedTransform
- TransformStyleTypes
- AnimateStyle
- StylesOrDefault
- AnimatedScrollViewProps
- FlatListPropsWithLayout
- \-\-\-
- EasingFunction
- EasingFunctionFactory
- \-\-\-
- WithDecayConfig
- \-\-\-
- WithSpringConfig
- \-\-\-
- WithTimingConfig
- \-\-\-
- FlatListPropsWithLayout
- \-\-\-
- AnimatedScrollViewProps
- \-\-\-
- AnimatedStyleProp
- \-\-\-
- InterpolateRGB
- InterpolateHSV
- \-\-\-
- KeyframeProps

___

Requires #4855 

## Test plan

CI + 🚀
piaskowyk pushed a commit that referenced this pull request Aug 4, 2023
<!-- Thanks for submitting a pull request! We appreciate you spending
the time to work on these changes. Please follow the template so that
the reviewers can easily understand what the code changes affect. -->

## Summary

During removal of `react-native-reanimated.d.ts` in #4519 I didn't
consider that some types were exported only in the aforementioned file,
e.g. `WithSpringConfig`. Therefore when we released `3.4.0` those types
disappear from public API. This PR restores lacking types from `.d.ts` -
but only the relevant ones, without Reanimated1 API.

## Types restored

### namespace Animated

- Extrapolate
- DerivedValue
- Adaptable
- TransformStyleTypes
- AdaptTransforms
- AnimatedTransform
- AnimateStyle
- StylesOrDefault
- AnimateProps
- EasingFunction
- addWhitelistedNativeProps
- addWhitelistedUIProps
- AnimatedScrollViewProps
- FlatListPropsWithLayout

### react-native-reanimated

- Adaptable
- AdaptTransforms
- AnimatedTransform
- TransformStyleTypes
- AnimateStyle
- StylesOrDefault
- AnimatedScrollViewProps
- FlatListPropsWithLayout
- \-\-\-
- EasingFunction
- EasingFunctionFactory
- \-\-\-
- WithDecayConfig
- \-\-\-
- WithSpringConfig
- \-\-\-
- WithTimingConfig
- \-\-\-
- FlatListPropsWithLayout
- \-\-\-
- AnimatedScrollViewProps
- \-\-\-
- AnimatedStyleProp
- \-\-\-
- InterpolateRGB
- InterpolateHSV
- \-\-\-
- KeyframeProps

___

Requires #4855 

## Test plan

CI + 🚀
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.

Typing seems incorrect for useAnimatedRef + FlatList + scrollToIndex
6 participants