#another copy of javascript when adding tsconfig.json

3 messages · Page 1 of 1 (latest)

native moth
#

@cloud citrus i just started to add tsconfig.json to my convex/ folder and it generated a copy of javascript file for every typescript file i have. why?

cloud citrusBOT
#

Let me check the knowledge base for you. One moment! :books:

#

Convex uses code generation to create code that is specific to your app's data model and API. When you run npx convex dev, it generates JavaScript files (.js) with TypeScript type definitions (.d.ts) in a convex/_generated directory. This is why you're seeing a JavaScript file for every TypeScript file in your project.

The generated code isn't required to use Convex, but it provides better autocompletion in your editor and more type safety if you're using TypeScript.

Here's the command to generate the code:

npx convex dev

This command creates a convex/_generated directory that contains api.js and api.d.ts, dataModel.d.ts, server.js and server.d.ts.

If you're seeing errors or unexpected behavior, make sure your tsconfig.json file is correctly configured. For example, you might need to add allowJs: true to your project-level tsconfig.json file.

For more information, you can refer to the Convex documentation (https://docs.convex.dev/generated-api) and the TypeScript documentation (https://www.typescriptlang.org/docs/handbook/tsconfig-json.html).

Sources:


Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: