Skip to content

feat: add TypeScript support #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ include the `jsonSpread.min.js` file from the dist folder

## TypeScript Support

This library includes TypeScript type definitions. You can import and use it in your TypeScript projects:
This library includes TypeScript type definitions. You can use it in your TypeScript projects:

```typescript
// CommonJS style
const jsonSpread = require('json-spread');

// OR ES Module style
import jsonSpread from 'json-spread';

// Use generics to specify the return type
Expand Down
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,7 @@ declare namespace jsonSpread {
export const spread: typeof JsonSpread.spread;
}

export = jsonSpread;
// Support for CommonJS exports
export = jsonSpread;
// Support for TypeScript usage in global environment
export as namespace jsonSpread;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "json-spread",
"version": "0.3.2",
"description": "simple javascript utility to spread nested json or javascript objects",
"main": "index.js",
"main": "dist/jsonSpread.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha",
Expand Down