Skip to content

Commit

Permalink
Merge pull request #176 from matrix-org/quenting/tsc-js
Browse files Browse the repository at this point in the history
Make tsc check JS files with @ts-check annotations
  • Loading branch information
sandhose authored Dec 10, 2024
2 parents 2313de1 + a9cd274 commit 74b73ae
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function loadModule() {
mod = await WebAssembly.compile(bytes);
}

/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
const instance = new WebAssembly.Instance(mod, {
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type
Expand Down
2 changes: 1 addition & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ async function loadModule() {
mod = await WebAssembly.compile(bytes);
}

/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
const instance = new WebAssembly.Instance(mod, {
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type
Expand Down
3 changes: 2 additions & 1 deletion node.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ bindings.__wbg_set_wasm(
{
get(_target, prop) {
const mod = loadModuleSync();
// @ts-expect-error: This results to an `any` type, which is fine
return initInstance(mod)[prop];
},
},
Expand Down Expand Up @@ -85,7 +86,7 @@ async function loadModule() {
function initInstance(mod) {
if (initialised) throw new Error("initInstance called twice");

/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
const instance = new WebAssembly.Instance(mod, {
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type
Expand Down
5 changes: 3 additions & 2 deletions node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ bindings.__wbg_set_wasm(
{
get(_target, prop) {
const mod = loadModuleSync();
// @ts-expect-error: This results to an `any` type, which is fine
return initInstance(mod)[prop];
},
},
Expand Down Expand Up @@ -80,12 +81,12 @@ async function loadModule() {
* Initializes the WASM module and returns the exports from the WASM module.
*
* @param {WebAssembly.Module} mod
* @returns {typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}
* @returns {typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}
*/
function initInstance(mod) {
if (initialised) throw new Error("initInstance called twice");

/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
const instance = new WebAssembly.Instance(mod, {
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type
Expand Down
15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@
],
"exports": {
".": {
"node": {
"require": "./node.js",
"import": "./node.mjs"
"require": {
"types": "./index.d.ts",
"node": "./node.js",
"default": "./index.js"
},
"require": "./index.js",
"import": "./index.mjs",
"types": "./index.d.ts"
"import": {
"types": "./index.d.ts",
"node": "./node.mjs",
"default": "./index.mjs"
}
}
},
"files": [
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"lib": ["DOM"]
"lib": ["DOM"],
"allowJs": true
},
"typedocOptions": {
"entryPoints": ["index.d.ts"],
Expand Down

0 comments on commit 74b73ae

Please sign in to comment.