D10S
D10S

Reputation: 1559

Declaration file for npm package

I published my first npm package but when downloaded it to one of my projects I found out that I need to implement the declaration file ("*.d.ts").

I have tried to integrate it but without success.

I've been wasting days on this issue. Please help.

package.json

{
    "main": "./dist/App",
    "name": "react-native-range-slider-expo",
    "description": "range slider",
    "license": "MIT",
    "homepage": "https://github.com/D10S60948/react-native-range-slider-expo#readme",
    "version": "1.0.8",
    "types": "./dist/App",
    "scripts": {
        "start": "expo start",
        "android": "expo start --android",
        "ios": "expo start --ios",
        "web": "expo start --web",
        "eject": "expo eject",
        "build": "tsc"
    },
    "dependencies": {
        "expo": "~38.0.8",
        "expo-status-bar": "^1.0.2",
        "react": "~16.11.0",
        "react-dom": "~16.11.0",
        "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.2.tar.gz",
        "react-native-gesture-handler": "^1.6.1",
        "react-native-svg": "^12.1.0",
        "react-native-web": "~0.11.7"
    },
    "devDependencies": {
        "@babel/core": "^7.8.6",
        "@types/react": "~16.9.41",
        "@types/react-native": "~0.62.13",
        "typescript": "~3.9.5"
    },
    "keywords": [
        "range",
        "slider",
        "expo"
    ]
}

tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "jsx": "react-native",
    "lib": ["dom", "esnext"],
    "moduleResolution": "node",
    "noEmit": true,
    "skipLibCheck": true,
    "resolveJsonModule": true,
    "strict": true,
    "declaration": true,
    "outDir": "./dist"
  }
}

Upvotes: 0

Views: 438

Answers (1)

D10S
D10S

Reputation: 1559

So I eventually managed to create this ".d.ts" file.

All I had to do is to remove from "tsconfig.json" this line

"noEmit": true

then run this line

tsc --emitDeclarationOnly

and VOILA!! the ".d.ts" was there, right next to the "tsx" file.

Upvotes: 1

Related Questions