question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to use soundex-code in Typescript

See original GitHub issue

I was trying to solve #245 and I’m a little confused about how to use soundex-code in Typescript.

I had previously tried soundex-code using just Node.js. This time, I was trying to set it up using Typescript. Since @types/soundex-code doesn’t exist, I tried making a custom type definition file: types/soundex-code/index.d.ts:

declare module 'soundex-code' {
    function soundex(
        value: any,
        maxLength?: any | undefined
    ): any;
    export = soundex;
}

and this is how I’m using it in src/index.ts:

import soundex from 'soundex-code';
console.log(soundex('lol'));

When I’m tsc-ing, this is what I get in dist/index.js:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const soundex_code_1 = require("soundex-code");
console.log(soundex_code_1.default('lol'));
//# sourceMappingURL=index.js.map

which doesn’t work. To get it to work, this is the required change:

- console.log(soundex_code_1.default('lol'));
+ console.log(soundex_code_1('lol'));

Can someone please identify what I’m doing wrong here? 🙂

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
alrifaycommented, Sep 30, 2020

try this import

import * as soundex from 'soundex-code';
3reactions
RaisinTencommented, Oct 1, 2020

Finally, I fixed it! 😃 src/index.ts:

import soundex from 'soundex-code';
console.log(soundex('lol'));

src/@types/soundex-code/index.d.ts:

declare module 'soundex-code' {
    export default function soundex(
        value: string,
        maxLength?: number | undefined
    ): string;
}

and I set "esModuleInterop": true in tsconfig.json. Yay!

EDIT: Here’s another way without using default: src/index.ts:

import soundex from 'soundex-code';
console.log(soundex('lol'));

src/@types/soundex-code/index.d.ts:

declare module 'soundex-code' {
    export = soundex;
    function soundex(
        value: string,
        maxLength?: number | undefined
    ): string;
}

+ set "esModuleInterop": true in tsconfig.json

Read more comments on GitHub >

github_iconTop Results From Across the Web

soundex-code - npm
Start using soundex-code in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >
TypeScript - Soundex algorithm implementation - Dirask
In this short article, we would like to show how to implement the Soundex algorithm in TypeScript. Below algorithm calculates Soundex code for...
Read more >
SQL Server SOUNDEX() Function - W3Schools
The SOUNDEX() function returns a four-character code to evaluate the similarity of two expressions. Note: The SOUNDEX() converts the string to a four-character ......
Read more >
SOUNDEX( ) function - HighBond
SOUNDEX( ) returns the American Soundex code for the evaluated string. All codes are one letter followed by three numbers. For example: "F634"....
Read more >
Documentation: 15: F.17. fuzzystrmatch - PostgreSQL
The soundex function converts a string to its Soundex code. The difference function converts two strings to their Soundex codes and then reports...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found