npm软件包的声明文件

时间:2020-07-18 15:56:10

标签: typescript npm npm-publish

我发布了我的第一个npm软件包,但是当将其下载到我的一个项目中时,我发现我需要实现声明文件(“ * .d.ts”)。

我尝试将其集成,但是没有成功。

我在这个问题上浪费了几天。 请帮忙。

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"
  }
}

1 个答案:

答案 0 :(得分:0)

所以我最终设法创建了这个“ .d.ts”文件。

我要做的就是从“ tsconfig.json”这一行中删除

"noEmit": true

然后运行此行

tsc --emitDeclarationOnly

还有VOILA! “ .d.ts”在那里,就在“ tsx”文件旁边。