Skip to content

Conversation

@phanect
Copy link

@phanect phanect commented Apr 6, 2025

Currently, currency-code/data is not typed and does not work with TypeScript code.

Example code and `tsc` output

test.ts

import currencies from "currency-codes/data";

console.log(currencies.map((currency) => currency.code).join("\n"));

Output by tsc --noEmit

/path/to/project-root/test.ts:1:24
Error: Could not find a declaration file for module 'currency-codes/data'. '/path/to/project-root/node_modules/.pnpm/currency-codes@2.2.0/node_modules/currency-codes/data.js' implicitly has an 'any' type.
  Try `npm i --save-dev @types/currency-codes` if it exists or add a new declaration (.d.ts) file containing `declare module 'currency-codes/data';` 
import currencies from "currency-codes/data";

/path/to/project-root/scripts/test.ts:3:29
Error: Parameter 'currency' implicitly has an 'any' type. 

console.log(currencies.map((currency) => currency.code).join("\n"));

This PR generates data.json instead of data.js so that you can import the data in the JSON format.
With this change, you can import the data from TypeScript code as follows:

import currencies from "currency-codes/data.json" with { type: "json" };

data.js is still generated for compatibility. You don't have to bump the major version this time.

I considered converting the entire codebase from JavaScript to TypeScript so that I could generate data.d.ts easily, but because I was not sure if you wanted to do so, I didn't rewrite it this time.

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