react-native-shake icon indicating copy to clipboard operation
react-native-shake copied to clipboard

Typescript support in beta

Open samducker opened this issue 1 year ago • 2 comments

Hi I have migrated to the beta as I could not get the previous versions to work at all in Expo SDK 52.

However I get this typescript error with the latest.

Could not find a declaration file for module 'react-native-shake'. '/Users/sam/project/node_modules/react-native-shake/lib/commonjs/index.js' implicitly has an 'any' type.
  There are types at ''/Users/sam/project/node_modules/react-native-shake/lib/typescript/module/src/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(7016)

samducker avatar Sep 02 '24 14:09 samducker

Hi @samducker as you can see in the suggestion, you may need to change moduleResolution field to Bundler. E.g:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true,
    "moduleResolution": "Bundler", // <-- this one
    "baseUrl": ".",
    "paths": {
      "~/*": ["src/*"],
      "@assets/*": ["assets/*"]
    }
  },
  "include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts"]
}

Doko-Demo-Doa avatar Sep 02 '24 17:09 Doko-Demo-Doa

I have applied a patch to be able to find the types:

diff --git a/node_modules/react-native-shake/package.json b/node_modules/react-native-shake/package.json
index 3dd6c0a..137d0fc 100644
--- a/node_modules/react-native-shake/package.json
+++ b/node_modules/react-native-shake/package.json
@@ -5,6 +5,7 @@
   "source": "./src/index.tsx",
   "main": "./lib/commonjs/index.js",
   "module": "./lib/module/index.js",
+  "types": "./lib/typescript/module/src/index.d.ts",
   "exports": {
     ".": {
       "import": {
@@ -15,7 +16,8 @@
         "types": "./lib/typescript/commonjs/src/index.d.ts",
         "default": "./lib/commonjs/index.js"
       }
-    }
+    },
+    "./types": "./lib/typescript/module/src/index.d.ts"
   },
   "files": [
     "src",

I have opened a PR: https://github.com/Doko-Demo-Doa/react-native-shake/pull/75

jeroen-van-dijk avatar Oct 23 '24 08:10 jeroen-van-dijk