What's The Difference Between .ts And .tsx - 简书
What's the difference between .ts and .tsx
Preface:What is the difference between .ts and .tsx extensions. Both are used as extensions for typescript files in react. So where should we use them?
Solution 1:
- Use .ts for pure TypeScript files.
- Use .tsx for files which contain JSX.
For example, a React component would be .tsx, but a file containing helper functions would be .ts.
Solution 2:
- tsx extension is used when we want to embed JSX elements inside the files while .ts is used for plain Typescript files and do not support adding JSX Elements.
Solution 3:All of the above answers are correct.
- .ts files contains only pure TypeScript
- .tsx have included JSX also.
On another point of view, you can copy everything from a .ts file and paste on .tsx file, and you don't need to modify anything. But if you're copying from a .tsx file you need to refactor it by removing the JSX elements.
Solution 4:
- when you use .tsx you can use JSX in that particular file while .ts gives you error.
相关阅读更多精彩内容
- Jest配置翻译自:https://jestjs.io/docs/zh-Hans/configuration最新更新:2020...秋名山车神12138阅读 21,949评论 0赞 7
- RN从零开始----JS错误信息列表{ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...Elbert_Z阅读 13,713评论 0赞 2
- RN模拟器报错中文翻译{ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...一粒沙随风飘摇阅读 13,792评论 0赞 3
- Angular2一些报错信息(json){ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...栗子雨阅读 12,425评论 0赞 3
- angular 报错指引"Unterminated string literal.": "未终止的字符串文本。", "Identifier...两个心阅读 12,667评论 0赞 4
友情链接更多精彩内容
- 如何在家给宠物做专业级美容修剪?
- 世卫组织如何促进猴痘防控的国际合作?
- 华山坐缆车攻略
推荐阅读
- 徐州有哪些值得一去的景区?
- 宜昌自驾神农架有哪些必玩景点和路线推荐?
- 狗狗皮肤病用什么药最有效?
- 菊花台自驾游有哪些必打卡的景点?
- 衡水哪里可以领养宠物?
- 狗肉煲的做法
- 养癞蛤蟆当宠物需要注意什么?
- 你家宠物会独立玩耍吗?盘点那些不粘人的小可爱!
- 宠物益生菌活菌数60000亿CFU/袋适合多宠重症抢救吗?
- 为什么有人会吃宠物狗肉?
- 狗狗美人鱼是什么?揭秘宠物界最可爱的混搭造型!
- 狗狗产后综合症有哪些症状和应对方法?
Từ khóa » Ts Và Tsx
-
Sự Khác Biệt Giữa Phần Mở Rộng .ts Và .tsx Là Gì. Cả Hai đều được Sử ...
-
What Is The Difference Between .ts And .tsx Extensions. Both Are Used ...
-
Is There Any Downside To Using .tsx Instead Of .ts All The Times In ... - Vba
-
What Is The Difference Between .ts And .tsx Extensions. Both ... - Dtuto
-
Giới Thiệu Typescript - Sự Khác Nhau Giữa Typescript Và Javascript
-
Sử Dụng Typescript Với ReactNative - Viblo
-
What Is The Difference Between .ts And .tsx ... - Query Threads
-
Học TypeScript Trong 30 Phút - TopDev
-
Documentation - Modules - TypeScript
-
Documentation - TypeScript 3.8
-
Anyone Can Explain The .ts File And .tsx File Use And Difference In ...
-
TS Versus TSX File Extension · React - at
-
TypeScript | Cypress Documentation
-
TSX File Extension - What Is A .tsx File And How Do I Open It?