I have a small little Typescript library that I am trying to publish to npmjs with the correct typings. However, it seems like it's not exporting the types file properly.
I have a simple method in the src/index.ts
file and typings from src/typings/index.d.ts
. (some function names/parameters renamed)
import { CoolData } from "./typings"; export const sampleExport = async (): Promise<CoolData[]> => {}
This is my tsconfig.json
{ "compilerOptions": { "target": "es5", "module": "commonjs", "moduleResolution": "node", "esModuleInterop": true, "resolveJsonModule": true, "lib": ["es6"], "declaration": true, "declarationMap": true, "declarationDir": "dist", "outDir": "dist", "rootDir": "src", "strict": true }, "include": ["src"], "exclude": ["node_modules", "**/*.spec.ts", "dist"] }
and partial package.json
"main": "dist/index", "types": "src/typings/index.d.ts", "files": [ "dist", "src/typings/index.d.ts" ],
When the index.d.ts
is generated inside the dist
folder, it has the wrong referenced path to the typings.
import { CoolData } from "./typings"; // Cannot find module './typings' or its corresponding type declarations.
Even though that's the case, I can still publish and use the library. However, the downside that it's returning an any
type for the method.
await sampleExport([]); // return type Promise<any>
Been trying to fix this for quite some time but to no avail. Hope that someone could help me out. Thank you.
https://stackoverflow.com/questions/66609455/typings-has-wrong-referenced-path March 13, 2021 at 10:03AM
没有评论:
发表评论