Skip to content

Migrate source files to Typescript #1280

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 28 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7111ae8
Add ts-nocheck rule to eslint
jgonet Dec 17, 2020
78f1431
Remove d.ts files from package.json, run eslint when linting
jgonet Dec 17, 2020
1f159f1
Remove unnecessary whitespace in .gitignore
jgonet Dec 17, 2020
77f04b7
Add babel plugins to package.json
jgonet Dec 17, 2020
0ee9469
Rename all files to ts/tsx extension and suppress TS & eslint errors
jgonet Dec 17, 2020
191ae04
Reformat and disable eslint in declaration files
jgonet Dec 17, 2020
90b1ac1
Add dist/ to packed dirs, add build & prepare command
jgonet Dec 17, 2020
48a9040
Add explicit return typo to createHandler to not use private Handler …
jgonet Dec 17, 2020
0f5dbde
Link to dist Swipeable and DrawerLayout to allow using scoped import
jgonet Dec 17, 2020
846db9a
Add types files for Drawer and Swipeable
jgonet Dec 17, 2020
0c842fa
Fix for TS being stubborn
jgonet Dec 17, 2020
1e065cf
Typos
jgonet Dec 17, 2020
d18a50e
Add tsconfig to the example app
jgonet Dec 18, 2020
1a0c075
Add package.json and podspec to exports
jgonet Dec 18, 2020
9efac2f
Copy Eslint config to examples
jgonet Dec 18, 2020
93332eb
Move Esling config file into correct location
jgonet Dec 18, 2020
f3a7a5a
Remove jest eslint plugin
jgonet Dec 22, 2020
f702efe
Add commands & eslint to Example
jgonet Dec 23, 2020
0a5fda7
Remove Swipeable and DrawerLayout
jgonet Dec 23, 2020
4f7e96c
Lint only project files
jgonet Dec 23, 2020
195230e
Update eslint and TS config
jgonet Dec 23, 2020
544b6d5
Update Travis config
jgonet Dec 23, 2020
4592826
Temporarily remove some flow annotations
jgonet Dec 23, 2020
cf0e8b0
Fix flag in ts-check command
jgonet Dec 28, 2020
5ba616f
Don't compile Examples in the root tsconfig
jgonet Dec 28, 2020
f25dcf4
Remove deleted files from package.json list
jgonet Dec 28, 2020
85ca6ed
Fix missing path specifier
jgonet Dec 28, 2020
314bb40
Remove exports, add subdir package.json
jgonet Dec 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
"react": { "version": "16" },
"import/resolver": {
"babel-module": {}
}
},
"import/core-modules": ["react-native-gesture-handler/Swipeable"]
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"env": { "browser": true, "node": true, "jest/globals": true },
"plugins": ["jest"],
"ignorePatterns": ["dist/**/*"],
"rules": {
"no-use-before-define": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
Expand All @@ -35,6 +37,8 @@
"@typescript-eslint/ban-ts-comment": [
"error",
{
// ↓ TODO ts-nocheck should be removed after transition to TS ↓
"ts-nocheck": "allow-with-description",
"ts-ignore": "allow-with-description",
"ts-expect-error": "allow-with-description"
}
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ jsconfig.json
.vscode

# TS

dist/
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ matrix:
- node_modules
script:
- yarn
- yarn tsc --noEmit
- yarn lint-check
- cd examples/Example
- yarn
- cd ../..
- yarn tsc --noEmit
- yarn lint-check
9 changes: 7 additions & 2 deletions DrawerLayout.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
declare module 'react-native-gesture-handler/DrawerLayout' {
import * as React from 'react'
import { Animated, StatusBarAnimation, StyleProp, ViewStyle } from 'react-native';
import * as React from 'react';
import {
Animated,
StatusBarAnimation,
StyleProp,
ViewStyle,
} from 'react-native';

export type DrawerPosition = 'left' | 'right';

Expand Down
2 changes: 0 additions & 2 deletions DrawerLayout.js

This file was deleted.

5 changes: 5 additions & 0 deletions DrawerLayout/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": "../dist/src/components/DrawerLayout",
"react-native": "../dist/src/components/DrawerLayout",
"types": "../DrawerLayout.d.ts"
}
16 changes: 11 additions & 5 deletions Swipeable.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
/* eslint-disable eslint-comments/no-unlimited-disable */
/* eslint-disable */
declare module 'react-native-gesture-handler/Swipeable' {
import * as React from 'react'
import * as React from 'react';
import { Animated, StyleProp, ViewStyle } from 'react-native';
import { PanGestureHandlerProperties } from 'react-native-gesture-handler'
type SwipeableExcludes = Exclude<keyof PanGestureHandlerProperties, 'onGestureEvent' | 'onHandlerStateChange'>
import { PanGestureHandlerProperties } from 'react-native-gesture-handler';
type SwipeableExcludes = Exclude<
keyof PanGestureHandlerProperties,
'onGestureEvent' | 'onHandlerStateChange'
>;

interface SwipeableProperties extends Pick<PanGestureHandlerProperties, SwipeableExcludes> {
interface SwipeableProperties
extends Pick<PanGestureHandlerProperties, SwipeableExcludes> {
enableTrackpadTwoFingerGesture?: boolean;
friction?: number;
leftThreshold?: number;
rightThreshold?: number;
overshootLeft?: boolean;
overshootRight?: boolean;
overshootFriction?: number,
overshootFriction?: number;
onSwipeableLeftOpen?: () => void;
onSwipeableRightOpen?: () => void;
onSwipeableOpen?: () => void;
Expand Down
2 changes: 0 additions & 2 deletions Swipeable.js

This file was deleted.

5 changes: 5 additions & 0 deletions Swipeable/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"main": "../dist/src/components/Swipeable",
"react-native": "../dist/src/components/Swipeable",
"types": "../Swipeable.d.ts"
}
47 changes: 47 additions & 0 deletions examples/Example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"root": true,
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"satya164"
],
"settings": {
"react": { "version": "16" },
"import/resolver": {
"babel-module": {}
}
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"env": { "browser": true, "node": true, "jest/globals": true },
"plugins": ["jest"],
"ignorePatterns": ["dist/**/*"],
"rules": {
"no-use-before-define": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"import/named": "off",
"react/sort-comp": "off",
"prefer-const": [
"error",
{
"destructuring": "all"
}
],
"@typescript-eslint/no-unused-vars": [
"error",
{ "argsIgnorePattern": "^_" }
],
"@typescript-eslint/no-use-before-define": "error",
"@typescript-eslint/ban-ts-comment": [
"error",
{
// ↓ TODO ts-nocheck should be removed after transition to TS ↓
"ts-nocheck": "allow-with-description",
"ts-ignore": "allow-with-description",
"ts-expect-error": "allow-with-description"
}
]
}
}
2 changes: 1 addition & 1 deletion examples/Example/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module.exports = {
presets: ['babel-preset-expo'],
plugins: [
'@babel/plugin-transform-modules-commonjs',
[
'module-resolver',
{
extensions: ['.js', '.ts', '.tsx'],
alias: {
'react-native-gesture-handler': '../../',
'react': './node_modules/react',
Expand Down
12 changes: 3 additions & 9 deletions examples/Example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ PODS:
- React
- RNGestureHandler (1.9.0):
- React-Core
- RNReanimated (1.13.2):
- React-Core
- RNScreens (2.15.0):
- React-Core
- Yoga (1.14.0)
Expand Down Expand Up @@ -366,7 +364,6 @@ DEPENDENCIES:
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNCMaskedView (from `../node_modules/@react-native-community/masked-view`)"
- RNGestureHandler (from `../../..`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- RNScreens (from `../node_modules/react-native-screens`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

Expand Down Expand Up @@ -446,8 +443,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/@react-native-community/masked-view"
RNGestureHandler:
:path: "../../.."
RNReanimated:
:path: "../node_modules/react-native-reanimated"
RNScreens:
:path: "../node_modules/react-native-screens"
Yoga:
Expand All @@ -457,7 +452,7 @@ SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
CocoaAsyncSocket: 694058e7c0ed05a9e217d1b3c7ded962f4180845
CocoaLibEvent: 2fab71b8bd46dd33ddb959f7928ec5909f838e3f
DoubleConversion: cde416483dac037923206447da6e1454df403714
DoubleConversion: 5805e889d232975c086db112ece9ed034df7a0b2
FBLazyVector: 878b59e31113e289e275165efbe4b54fa614d43d
FBReactNativeSpec: 7da9338acfb98d4ef9e5536805a0704572d33c2f
Flipper: be611d4b742d8c87fbae2ca5f44603a02539e365
Expand All @@ -467,8 +462,8 @@ SPEC CHECKSUMS:
Flipper-PeerTalk: 116d8f857dc6ef55c7a5a75ea3ceaafe878aadc9
Flipper-RSocket: 64e7431a55835eb953b0bf984ef3b90ae9fdddd7
FlipperKit: ab353d41aea8aae2ea6daaf813e67496642f3d7d
Folly: aeb27d02cdff07ca01f8a8a5a6dd5bcaf6be6f70
glog: 2ad46e202fbaa5641fceb4b2af37dcd88fd8762d
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
glog: 1f3da668190260b06b429bb211bfbee5cd790c28
OpenSSL-Universal: ff34003318d5e1163e9529b08470708e389ffcdd
RCTRequired: 48884c74035a0b5b76dbb7a998bd93bcfc5f2047
RCTTypeSafety: edf4b618033c2f1c5b7bc3d90d8e085ed95ba2ab
Expand All @@ -495,7 +490,6 @@ SPEC CHECKSUMS:
ReactCommon: 4167844018c9ed375cc01a843e9ee564399e53c3
RNCMaskedView: 5a8ec07677aa885546a0d98da336457e2bea557f
RNGestureHandler: 9b7e605a741412e20e13c512738a31bd1611759b
RNReanimated: e03f7425cb7a38dcf1b644d680d1bfc91c3337ad
RNScreens: 2ad555d4d9fa10b91bb765ca07fe9b29d59573f0
Yoga: 7d13633d129fd179e01b8953d38d47be90db185a
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
10 changes: 6 additions & 4 deletions examples/Example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"ios": "react-native run-ios",
"start": "react-native start",
"test": "jest",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
"lint": "eslint . --ext .js,.jsx,.ts,.tsx",
"ts-check": "yarn tsc --noEmit",
"lint-check": "yarn eslint src/ && yarn prettier --check src/"
},
"dependencies": {
"@react-native-community/masked-view": "^0.1.10",
Expand All @@ -34,9 +36,9 @@
"@typescript-eslint/parser": "^4.9.1",
"babel-jest": "^25.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-preset-expo": "^8.3.0",
"eslint": "^7.15.0",
"eslint-plugin-jest": "^24.1.3",
"eslint": "^7.16.0",
"eslint-import-resolver-babel-module": "^5.2.0",
"eslint-plugin-import": "^2.22.1",
"glob-to-regexp": "^0.4.1",
"jest": "^25.1.0",
"metro-config": "^0.64.0",
Expand Down
1 change: 1 addition & 0 deletions examples/Example/src/touchables/index.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck TODO(TS) provide types
import React, { Component } from 'react';
import { StackScreenProps } from '@react-navigation/stack';

Expand Down
30 changes: 30 additions & 0 deletions examples/Example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"compilerOptions": {
"baseUrl": ".",
// TODO(TS) Remove after we migrate to TS entirely
"paths": {
"react-native-gesture-handler": [
"../../react-native-gesture-handler.d.ts"
],
"react-native-gesture-handler/Swipeable": ["../../Swipeable.d.ts"],
"react-native-gesture-handler/DrawerLayout": ["../../DrawerLayout.d.ts"]
},
"esModuleInterop": true,
"jsx": "react-native",
"lib": ["esnext"],
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext",
"allowJs": true,
"noStrictGenericChecks": false,
"forceConsistentCasingInFileNames": true,
"noImplicitUseStrict": false,
"noUnusedParameters": true,
"noUnusedLocals": true,
"outDir": "./dist"
},
"include": ["src/**/*.ts", "src/**/*.tsx", "index.js"]
}
Loading