Skip to content

Conversation

@ryanande
Copy link
Owner

@ryanande ryanande commented Jan 7, 2026

Add TypeScript Type Definitions

Problem

The jscombguid package is JavaScript-only and doesn't include TypeScript type definitions. There's no @types/jscombguid package available. With "strict": true in tsconfig.json, TypeScript requires type information for all imports, causing the tsc -b step to fail for consuming applications.

Solution

This PR adds native TypeScript type definitions to the library, eliminating the need for a separate @types/jscombguid package. The type definitions are automatically included in the build output and published with the package.

Changes

1. TypeScript Definition File (src/index.d.ts)

  • Added TypeScript declaration file defining the generateSequentialGuid function
  • Function signature: () => string
  • Includes comprehensive JSDoc comments matching the source code
  • Provides type information for the default export

2. Build Script (scripts/copy-types.js)

  • Created cross-platform Node.js script to copy .d.ts files from src/ to lib/ during build
  • Uses top-level await for modern ES module syntax
  • Ensures type definitions are included in the published package

3. Build Process Updates (package.json)

  • Added copy-types script to the build pipeline
  • Updated build script to include type definition copying step
  • Build flow: clean → lint → compile → copy-types → test

Benefits

TypeScript Support: Consuming applications with strict TypeScript can now use the library without errors
No External Dependencies: Type definitions are bundled with the package (no need for @types/jscombguid)
Better Developer Experience: IDEs will provide autocomplete and type checking
Backward Compatible: JavaScript consumers are unaffected

Testing

  • ✅ Type definitions are copied correctly during build
  • ✅ Script runs successfully on Node.js
  • ✅ All existing tests pass
  • ✅ Linting passes with no errors

Usage Example

import generateSequentialGuid from 'jscombguid';

const guid: string = generateSequentialGuid();
console.log(guid); // TypeScript knows this is a string

Related

Fixes the issue where consuming applications with "strict": true in tsconfig.json fail to compile when importing this library.

- Add TypeScript definition file (src/index.d.ts) for generateSequentialGuid function
- Add build script to copy .d.ts files from src/ to lib/ during build
- Update build process to include type definition copying step
- Fixes issue where consuming applications with strict TypeScript fail to compile
@ryanande ryanande merged commit 21a32ba into main Jan 7, 2026
1 check passed
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.

2 participants