简体   繁体   中英

Is there any way to use typescript file in react redux project?

I got a completely developed project in react,redux and typescript. Le me say it project "A". I am working on project "B" with react and redux using .jsx extention. Now I want to reuse a module from project A(.ts extension files) in project B. How can I use .ts files along with jsx files in project B?

You'd have to add a typescript loader to your webpack config, so webpack knows it can also load in ts files.

Now simply require() or import the file (depends on which one you already use) in javascript.

Make sure you don't use default exports but named exports, cause default export works a bit different in require() vs. import .. from.

On the other hand you can always make project A generate the JS file for you and use that one in proj B.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM