From faad631fe57bcc68f3bb470d60bb11a97460dbde Mon Sep 17 00:00:00 2001 From: Charles Mangwa Date: Fri, 19 Apr 2024 09:59:48 +0200 Subject: [PATCH] feat: set up TypeScript declaration files generation This process was based on a TypeScript official guide: https://www.typescriptlang.org/docs/handbook/declaration-files/dts-from-js.html. --- .gitignore | 3 +-- package.json | 41 +++++++++++++++++++++++------------------ tsconfig.json | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 20 deletions(-) create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore index 8a6fe18..424d6da 100644 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,6 @@ DerivedData *.xcuserstate - *.hprof # Android/IntelliJ @@ -44,7 +43,6 @@ local.properties npm-debug.log yarn-error.log - # BUCK buck-out/ \.buckd/ @@ -66,3 +64,4 @@ buck-out/ *.bundle sample/ios/Podfile.lock sample/android/app/google-services.json +typescript/* diff --git a/package.json b/package.json index ac93ea8..29d280b 100644 --- a/package.json +++ b/package.json @@ -1,20 +1,25 @@ { - "name": "react-native-emarsys-wrapper", - "version": "1.17.0", - "description": "React Native wrapper for Emarsys SDK", - "main": "index.js", - "type": "module", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [ - "react-native", - "Emarsys" - ], - "author": "emarsys", - "license": "MIT", - "peerDependencies": { - "react": ">=17.0.2", - "react-native": ">=0.67.3" - } + "name": "react-native-emarsys-wrapper", + "version": "1.17.0", + "description": "React Native wrapper for Emarsys SDK", + "main": "index.js", + "types": "typescript/index.d.ts", + "type": "module", + "scripts": { + "prepare": "tsc", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [ + "react-native", + "Emarsys" + ], + "author": "emarsys", + "license": "MIT", + "devDependencies": { + "typescript": ">=3.7.2" + }, + "peerDependencies": { + "react": ">=17.0.2", + "react-native": ">=0.67.3" + } } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..63640ff --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,17 @@ +{ + // Tells TypeScript where to look for files to work with. + "include": ["index.js", "src/**/*"], + "compilerOptions": { + // Tells TypeScript to read JS files, as normally they are ignored as source files. + "allowJs": true, + // Generate .d.ts files. + "declaration": true, + // This compiler run should only output .d.ts files. + "emitDeclarationOnly": true, + // Types should go into this directory. + // Removing this option will place the .d.ts files next to their .js source files. + "outDir": "typescript", + // Generate declaration files to go to js file when using IDE functions like "Go to Definition". + "declarationMap": true + } +}