Skip to content

Commit 74b73ae

Browse files
authored
Merge pull request #176 from matrix-org/quenting/tsc-js
Make tsc check JS files with @ts-check annotations
2 parents 2313de1 + a9cd274 commit 74b73ae

File tree

6 files changed

+18
-12
lines changed

6 files changed

+18
-12
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function loadModule() {
6363
mod = await WebAssembly.compile(bytes);
6464
}
6565

66-
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
66+
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
6767
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
6868
const instance = new WebAssembly.Instance(mod, {
6969
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type

index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ async function loadModule() {
6363
mod = await WebAssembly.compile(bytes);
6464
}
6565

66-
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
66+
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
6767
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
6868
const instance = new WebAssembly.Instance(mod, {
6969
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type

node.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bindings.__wbg_set_wasm(
3535
{
3636
get(_target, prop) {
3737
const mod = loadModuleSync();
38+
// @ts-expect-error: This results to an `any` type, which is fine
3839
return initInstance(mod)[prop];
3940
},
4041
},
@@ -85,7 +86,7 @@ async function loadModule() {
8586
function initInstance(mod) {
8687
if (initialised) throw new Error("initInstance called twice");
8788

88-
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
89+
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
8990
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
9091
const instance = new WebAssembly.Instance(mod, {
9192
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type

node.mjs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ bindings.__wbg_set_wasm(
3535
{
3636
get(_target, prop) {
3737
const mod = loadModuleSync();
38+
// @ts-expect-error: This results to an `any` type, which is fine
3839
return initInstance(mod)[prop];
3940
},
4041
},
@@ -80,12 +81,12 @@ async function loadModule() {
8081
* Initializes the WASM module and returns the exports from the WASM module.
8182
*
8283
* @param {WebAssembly.Module} mod
83-
* @returns {typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}
84+
* @returns {typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}
8485
*/
8586
function initInstance(mod) {
8687
if (initialised) throw new Error("initInstance called twice");
8788

88-
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d")}} */
89+
/** @type {{exports: typeof import("./pkg/matrix_sdk_crypto_wasm_bg.wasm.d.ts")}} */
8990
// @ts-expect-error: Typescript doesn't know what the instance exports exactly
9091
const instance = new WebAssembly.Instance(mod, {
9192
// @ts-expect-error: The bindings don't exactly match the 'ExportValue' type

package.json

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,16 @@
2020
],
2121
"exports": {
2222
".": {
23-
"node": {
24-
"require": "./node.js",
25-
"import": "./node.mjs"
23+
"require": {
24+
"types": "./index.d.ts",
25+
"node": "./node.js",
26+
"default": "./index.js"
2627
},
27-
"require": "./index.js",
28-
"import": "./index.mjs",
29-
"types": "./index.d.ts"
28+
"import": {
29+
"types": "./index.d.ts",
30+
"node": "./node.mjs",
31+
"default": "./index.mjs"
32+
}
3033
}
3134
},
3235
"files": [

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"extends": "@tsconfig/node18/tsconfig.json",
33
"compilerOptions": {
4-
"lib": ["DOM"]
4+
"lib": ["DOM"],
5+
"allowJs": true
56
},
67
"typedocOptions": {
78
"entryPoints": ["index.d.ts"],

0 commit comments

Comments
 (0)