Skip to content

Conversation

@ocavue
Copy link

@ocavue ocavue commented Nov 13, 2025

Currently, the TypeScript declarations are stored in .ts files, and we use tsc to compile them into .d.ts files. This step is unnecessary, and we don't really want all those .js and .js.map files under dist/ . We can simply place all TypeScript declarations directly in .d.ts files.

This pull request includes the following changes:

  1. Rename all .ts files to .d.ts files under src/.
  2. Update the types field in package.json to point directly to src/index.d.ts.
  3. Modify tsconfig.json:
    • Add "noEmit": true so that no ./dist/**/*.d.ts files will be generated anymore.
    • Add "skipLibCheck": false to ensure that tsc still verifies our code. More on that below.
    • Add "types": [] to prevent tsc from accidentally picking node_modules/@types/node. This will also be the default behavior in the upcoming TypeScript 6.0: Change default of types to [] in tsconfig.json microsoft/TypeScript#62195

Please note that I did not remove the "build": "tsc" script in package.json. We will need this script to check our .d.ts files under src/. I tested it using the following example:

# Modify a .d.ts file to rename an import to an incorrect name
❯ git diff src/types/opencv/softfloat.d.ts | tee
diff --git a/src/types/opencv/softfloat.d.ts b/src/types/opencv/softfloat.d.ts
index 2b9fa33..5d2a206 100644
--- a/src/types/opencv/softfloat.d.ts
+++ b/src/types/opencv/softfloat.d.ts
@@ -1,4 +1,4 @@
-import type { bool, int, int32_t, int64_t, uint32_t, uint64_t } from "./_types";
+import type { bool, int, int32_T, int64_t, uint32_t, uint64_t } from "./_types";

 export declare class softfloat {
   public v: uint32_t;

# Run `build` script again, and `tsc` would report the error
❯ npm run build

> @techstark/opencv-js@4.12.0-release.1 build
> tsc

src/types/opencv/softfloat.d.ts:1:26 - error TS2724: '"./_types"' has no exported member named 'int32_T'. Did you mean 'int32_t'?

1 import type { bool, int, int32_T, int64_t, uint32_t, uint64_t } from "./_types";
                           ~~~~~~~

src/types/opencv/softfloat.d.ts:14:30 - error TS2552: Cannot find name 'int32_t'. Did you mean 'uint32_t'?

14   public constructor(arg176: int32_t);
                                ~~~~~~~


Found 2 errors in the same file, starting at: src/types/opencv/softfloat.d.ts:1

@ocavue ocavue marked this pull request as ready for review November 13, 2025 08:27
@ocavue ocavue force-pushed the ocavue/rename-ts-to-dts branch from 4dd6dc9 to 35381d6 Compare November 13, 2025 08:33
@ocavue ocavue mentioned this pull request Nov 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant