-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
fix: TypeScript bloat #3603
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
lukewalczak
merged 2 commits into
callstack:main
from
DimitarNestorov:chore/fix-typescript-bloat
Jan 23, 2023
Merged
fix: TypeScript bloat #3603
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| const { promises: fs } = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| const root = path.resolve(__dirname, '..'); | ||
| const output = path.join(root, 'lib', 'typescript'); | ||
|
|
||
| /** | ||
| * List of React Native props not used by React Native Paper. | ||
| * Feel free to delete props from this list when | ||
| * React Native Paper has defined/uses one with the same name. | ||
| * This script was originally created to detect if TypeScript | ||
| * has exported a large union of props from ViewProps. | ||
| * More info: https://github.com/callstack/react-native-paper/pull/3603 | ||
| */ | ||
| const unusedViewProps = [ | ||
| 'nativeID', | ||
| 'accessibilityActions', | ||
| 'accessibilityRole', | ||
| 'accessibilityValue', | ||
| 'onAccessibilityAction', | ||
| 'accessibilityLabelledBy', | ||
| 'accessibilityLiveRegion', | ||
| 'accessibilityLanguage', | ||
| 'accessibilityViewIsModal', | ||
| 'onAccessibilityEscape', | ||
| 'onAccessibilityTap', | ||
| 'onMagicTap', | ||
| 'accessibilityIgnoresInvertColors', | ||
| 'hitSlop', | ||
| 'removeClippedSubviews', | ||
| 'collapsable', | ||
| 'needsOffscreenAlphaCompositing', | ||
| 'renderToHardwareTextureAndroid', | ||
| 'shouldRasterizeIOS', | ||
| 'isTVSelectable', | ||
| 'hasTVPreferredFocus', | ||
| 'tvParallaxProperties', | ||
| 'tvParallaxShiftDistanceX', | ||
| 'tvParallaxShiftDistanceY', | ||
| 'tvParallaxTiltAngle', | ||
| 'tvParallaxMagnification', | ||
| 'onStartShouldSetResponder', | ||
| 'onMoveShouldSetResponder', | ||
| 'onResponderEnd', | ||
| 'onResponderGrant', | ||
| 'onResponderReject', | ||
| 'onResponderMove', | ||
| 'onResponderRelease', | ||
| 'onResponderStart', | ||
| 'onResponderTerminationRequest', | ||
| 'onResponderTerminate', | ||
| 'onStartShouldSetResponderCapture', | ||
| 'onMoveShouldSetResponderCapture', | ||
| 'onTouchStart', | ||
| 'onTouchMove', | ||
| 'onTouchEnd', | ||
| 'onTouchCancel', | ||
| 'onTouchEndCapture', | ||
| 'onPointerEnter', | ||
| 'onPointerEnterCapture', | ||
| 'onPointerLeave', | ||
| 'onPointerLeaveCapture', | ||
| 'onPointerMove', | ||
| 'onPointerMoveCapture', | ||
| 'onPointerCancel', | ||
| 'onPointerCancelCapture', | ||
| 'onPointerDown', | ||
| 'onPointerDownCapture', | ||
| 'onPointerUp', | ||
| 'onPointerUpCapture', | ||
| 'onHoverIn', | ||
| 'onHoverOut', | ||
| 'cancelable', | ||
| 'delayHoverIn', | ||
| 'delayHoverOut', | ||
| 'pressRetentionOffset', | ||
| 'android_disableSound', | ||
| 'android_ripple', | ||
| 'testOnly_pressed', | ||
| 'unstable_pressDelay', | ||
| ]; | ||
|
|
||
| async function* getFiles(directory) { | ||
| const entries = await fs.readdir(directory, { withFileTypes: true }); | ||
| for (const entry of entries) { | ||
| const res = path.resolve(directory, entry.name); | ||
| if (entry.isDirectory()) { | ||
| yield* getFiles(res); | ||
| } else { | ||
| yield res; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| async function main() { | ||
| for await (const file of getFiles(output)) { | ||
| const content = await fs.readFile(file); | ||
| for (const prop of unusedViewProps) { | ||
| if (content.includes(prop)) { | ||
| throw new Error( | ||
| `Found text '${prop}' in '${file}'. Please use the wrapped 'forwardRef' in 'src/utils/forwardRef.ts', export some return types, or modify 'scripts/typescript-output-lint.js'` | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| console.log('✅ No React Native props mentioned in TypeScript files'); | ||
| } | ||
|
|
||
| main().catch((reason) => { | ||
| console.error(reason); | ||
| process.exit(1); | ||
| }); |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { | ||
| forwardRef as reactForwardRef, | ||
| ForwardRefRenderFunction, | ||
| PropsWithoutRef, | ||
| RefAttributes, | ||
| ForwardRefExoticComponent, | ||
| } from 'react'; | ||
|
|
||
| export type ForwarRefComponent<T, P = {}> = ForwardRefExoticComponent< | ||
| PropsWithoutRef<P> & RefAttributes<T> | ||
| >; | ||
|
|
||
| /** | ||
| * TypeScript generated a large union of props from `ViewProps` in | ||
| * `d.ts` files when using `React.forwardRef`. To prevent this | ||
| * `ForwarRefComponent` was created and exported. Use this | ||
| * `forwardRef` instead of `React.forwardRef` so you don't have to | ||
| * import `ForwarRefComponent`. | ||
| * More info: https://github.com/callstack/react-native-paper/pull/3603 | ||
| */ | ||
| export const forwardRef: <T, P = {}>( | ||
| render: ForwardRefRenderFunction<T, P> | ||
| ) => ForwarRefComponent<T, P> = reactForwardRef; | ||
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.
Uh oh!
There was an error while loading. Please reload this page.