How to use soundex-code in Typescript
See original GitHub issueI 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:
- Created 3 years ago
- Comments:10 (9 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
try this import
Finally, I fixed it! 😃
src/index.ts
:src/@types/soundex-code/index.d.ts
:and I set
"esModuleInterop": true
intsconfig.json
. Yay!EDIT: Here’s another way without using
default
:src/index.ts
:src/@types/soundex-code/index.d.ts
:+ set
"esModuleInterop": true
intsconfig.json