4

I have inherited a bit of a legacy project with JSX. I am in the process of converting the JSX into TSX.

Currently while importing JSX and JS files in TSX. I get an error Cannot find module 'config/abc_module' or its corresponding type declarations..

I understand the types are missing as it is a JS file. I have added JSDoc types, but nothing seems to help. What would be the best way to add types in JSX files to use them in TSX.

I have quite a few files in JS, and some I cannot even convert due to specific reasons. I have searched a lot and read quite a few articles, but can't seem to find any specific way forward. Any help would be appreciated. Thanks in advance.

Abhirup Pal
  • 152
  • 2
  • 11

2 Answers2

2
  1. make a global.d.ts file in your root directory where all your code files are
  2. in file write lines:

declare module 'path/to/your/js/or/jsx'

now these js/jsx files will resolve as modules to import in your typescript code! enjoy!

Edit: also make sure your tsconfig.json is configured to let you mix ts/js

bturner1273
  • 660
  • 7
  • 18
0

You can probably just change the extensions from .js or .jsx -> .tsx. TypeScript is supposed to be a superset of JavaScript.

Also see this previous question

Neal Burns
  • 839
  • 4
  • 5
  • By default TS is a superset of JS, but this isn't always true because some projects use strict ts, and have the build fail on errors. – aaaidan Feb 24 '23 at 03:29