-
Notifications
You must be signed in to change notification settings - Fork 734
Ref Typings #2885
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
Merged
Merged
Ref Typings #2885
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b1149bd
Changed forwardRef typings
nitzanyiz fd3a4df
Removed test component
nitzanyiz b53f3a3
Added typings to forwardRef to support ref typing interface
nitzanyiz 76738f6
Added typings to forwardRef and asBaseComponents
nitzanyiz 9e678a8
Changed static to object by default. "Fixed" static properties typings
nitzanyiz a0d9dee
Changed injected ref typing
nitzanyiz 4d06fd7
Fixed button typing errors
nitzanyiz 700b5e2
Moved ButtonStatis to types file
nitzanyiz d15753c
Added component statics extraction type
nitzanyiz 34afc9d
Added usage of components statics extraction type
nitzanyiz 2641169
Added component statics usage to scroll bar
nitzanyiz 40eb1e5
Merge remote-tracking branch 'origin' into infra/RefTypings
nitzanyiz 2d3ba2e
Fixed Slider interface typings and screen
nitzanyiz fee312b
Fixed TextField ref typings
nitzanyiz fed6f62
Added fadedScrollView ref interface
nitzanyiz 0dafa42
Fixed icon statics typings
nitzanyiz fdf7c34
Fixed gradient slider statics
nitzanyiz f0e702a
Fixed FadedScrollView ref typing in tabController
nitzanyiz 200fd5f
Last TS fixes
ethanshar f7ea4c7
Fixed lint errors
nitzanyiz 7e65b5e
Removed empty ref interfaces
nitzanyiz cb24523
TS fix
nitzanyiz 83af2e0
Fixed imports and formatting
nitzanyiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
import React from 'react'; | ||
import React, {ComponentType, ForwardedRef} from 'react'; | ||
import hoistStatics from 'hoist-non-react-statics'; | ||
|
||
export interface ForwardRefInjectedProps { | ||
export interface ForwardRefInjectedProps<T = any> { | ||
/** | ||
* The forwarded ref of the containing element | ||
*/ | ||
forwardedRef: any; | ||
forwardedRef: ForwardedRef<T>; | ||
} | ||
|
||
export default function forwardRef<P = any, STATICS = {}>(WrappedComponent: React.ComponentType<P>): React.ComponentType<P> & STATICS { | ||
function forwardRef(props: P, ref: any) { | ||
export default function forwardRef<P, STATICS = {}, RefInterface = any>(WrappedComponent: ComponentType<P & ForwardRefInjectedProps<RefInterface>>) { | ||
function forwardRef(props: P, ref: ForwardedRef<RefInterface>) { | ||
return <WrappedComponent {...props} forwardedRef={ref}/>; | ||
} | ||
|
||
const ForwardedComponent = React.forwardRef(forwardRef); | ||
const ForwardedComponent = React.forwardRef<RefInterface, P>(forwardRef); | ||
|
||
hoistStatics(ForwardedComponent, WrappedComponent); | ||
//@ts-ignore | ||
ForwardedComponent.displayName = WrappedComponent.displayName; | ||
//@ts-ignore | ||
ForwardedComponent.propTypes = WrappedComponent.propTypes; | ||
//@ts-ignore | ||
ForwardedComponent.defaultProps = WrappedComponent.defaultProps; | ||
|
||
return ForwardedComponent as any; | ||
return ForwardedComponent as typeof ForwardedComponent & STATICS; | ||
} |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import React, {useCallback, useEffect, useState} from 'react'; | |
import {StyleProp, ViewStyle} from 'react-native'; | ||
import {Colors} from '../../style'; | ||
import {asBaseComponent, forwardRef, ForwardRefInjectedProps} from '../../commons/new'; | ||
import {ComponentStatics} from '../../typings/common'; | ||
import Slider, {SliderProps} from './index'; | ||
import {Slider as NewSlider} from '../../incubator'; | ||
import {SliderContextProps} from './context/SliderContext'; | ||
|
@@ -192,7 +193,6 @@ const GradientSlider = (props: Props) => { | |
return ( | ||
<SliderComponent | ||
{...others} | ||
//@ts-expect-error | ||
ref={forwardedRef} | ||
onReset={reset} | ||
renderTrack={renderTrack} | ||
|
@@ -213,4 +213,5 @@ GradientSlider.displayName = 'GradientSlider'; | |
GradientSlider.types = GradientSliderTypes; | ||
|
||
// eslint-disable-next-line max-len | ||
export default asBaseComponent<GradientSliderProps, typeof GradientSlider>(forwardRef(asSliderGroupChild(forwardRef(GradientSlider)))); | ||
// @ts-expect-error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you know why we have an error here? |
||
export default asBaseComponent<GradientSliderProps, ComponentStatics<typeof GradientSlider>>(forwardRef(asSliderGroupChild(forwardRef(GradientSlider)))); |
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
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
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
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
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to pass null here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using it without null, the type of the ref is Ref<SliderRef | undefined> which causes an error. This error also occurs with regular react native refs. For example using React Native TextInput.
