Skip to content

Commit

Permalink
Improve: TypeScript annotations (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlarmstrongiv authored Nov 12, 2023
1 parent 494b9f0 commit 6a5e009
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ jobs:
npm install
npm ci
npm test
npm run typegen
- name: Publish
uses: JS-DevTools/npm-publish@v2
Expand Down
2 changes: 1 addition & 1 deletion javascript/usearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Index {
/**
* Constructs a new index.
*
* @param {number} dimensionsOrConfigs
* @param {(number | {dimensions: number, metric: MetricKind = MetricKind.Cos, quantization: ScalarKind = ScalarKind.F32, connectivity: number = 0, expansion_add: number = 0, expansion_search: number = 0, multi: boolean = false})} dimensionsOrConfigs
* @param {MetricKind} [metric=MetricKind.Cos] - Optional, default is 'cos'.
* @param {ScalarKind} [quantization=ScalarKind.F32] - Optional, default is 'f32'.
* @param {number} [connectivity=0] - Optional, default is 0.
Expand Down
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,24 @@
},
"scripts": {
"test": "node --test ./javascript/usearch.test.js",
"install": "node-gyp rebuild"
"install": "node-gyp rebuild",
"typegen": "npx tsc"
},
"devDependencies": {
"typescript": "^5.1.6"
}
},
"exports": {
".": {
"types": "./javascript/types/usearch.d.ts",
"require": "./javascript/usearch.js"
},
"./package.json": "./package.json"
},
"typesVersions": {
"*": {
"*": [
"./javascript/types/usearch.d.ts"
]
}
}
}
21 changes: 21 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
// Change this to match your project
"include": ["javascript/usearch.js"],
"compilerOptions": {
// Tells TypeScript to read JS files, as
// normally they are ignored as source files
"allowJs": true,
// Generate d.ts files
"declaration": true,
// This compiler run should
// only output d.ts files
"emitDeclarationOnly": true,
// Types should go into this directory.
// Removing this would place the .d.ts files
// next to the .js files
"outDir": "javascript/types",
// go to js file when using IDE functions like
// "Go to Definition" in VSCode
"declarationMap": true
}
}

0 comments on commit 6a5e009

Please sign in to comment.