I just published a npm package written in typescript. Currently I have a lot of trouble getting the definition recognized by typescript (webback and vscode). The only solution that worked so far was to create a folder with the definition in node_modules/@types
Briefly this is 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 keep 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 it is just a small mistake somewhere. Basically I want to get the nanoBind() and nanoBindAll() declared as globals.
Edit
Additional things I tried. Nothing works.
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"
]
}
/// <referenceis for global script files, as a package, you would not use that syntax. Justimport '...'.typings. And various other things. It just refuses to register as a definition. The definition is definitely in the package.types/typings: ...in your package.json. See any of my packages for example. e.g.color-map