Recently, I released an npm package that was written in typescript. However, I have been facing difficulties in getting the definition recognized by typescript (webback and vscode). The only workaround that has worked for me so far is creating a folder with the definition in node_modules/@types
Here is a brief overview of my package setup:
tsconfig.json
{
"compilerOptions": {
...
"outDir": "./lib/",
"declaration": true,
"declarationDir": "./src/",
}
}
package.json
{
...
"types": "./index.d.ts",
}
index.d.ts
/// <reference path="src/nano-data-binding.d.ts" />
src/nano-data-binding.d.ts
I've kept it in /src
because it's autogenerated and I cannot control the path of the import. Also, if I try to use only declare var ...
without import export
statements to get a script instead of a module.
import { StringOrHTMLElement } from './interfaces/nano-data-binding';
export declare function nanoBind(parent: HTMLElement, ...selectors: StringOrHTMLElement[]): HTMLElement[];
export declare function nanoBindAll(parent: HTMLElement, ...selectors: string[]): HTMLElement[];
Feel free to install the package, maybe there's just a small mistake somewhere. My goal is to have the nanoBind()
and nanoBindAll()
declared as globals.
Edit
Additional things I tried. None of them seem to work.
package.json - Npm package
{
...
"types": "lib/nano-data-binding.d.ts",
"typings": "lib/nano-data-binding.d.ts",
"typescript": {
"definition": "lib/nano-data-binding.d.ts"
},
}
tsconfig.json - Local project
{
...
"files": [
"node_modules/nano-data-binding/lib/nano-data-binding.d.ts"
]
}