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,959评论 0赞 7
- RN从零开始----JS错误信息列表{ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...Elbert_Z阅读 10,974评论 0赞 2
- RN模拟器报错中文翻译{ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...一粒沙随风飘摇阅读 11,194评论 0赞 3
- Angular2一些报错信息(json){ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...栗子雨阅读 8,062评论 0赞 3
- angular 报错指引"Unterminated string literal.": "未终止的字符串文本。", "Identifier...两个心阅读 8,539评论 0赞 4
友情链接更多精彩内容
- 美国西雅图攻略
- 投资一家宠物酒店需要多少钱?
- 石林峡风景区适合带宠物一起游玩吗?
推荐阅读
- 如何为狗狗挑选合适的冠军级狗粮?
- 秦岭骑行路线有哪些值得推荐的?
- 威尔士自驾游有哪些必打卡的景点?
- 九寨沟自驾游住哪里好
- 土耳其自驾游需要多少费用?
- 宠物益生菌怎么喂才正确?新手必看喂养指南!
- 南方秋天为什么天黑得越来越早?昼短夜长开始明显
- 狗狗手肘长了一个包
- 成都泸沽湖攻略
- 汉川到宜昌自驾游
- 高淳有什么好吃的小吃
- 三明古溪星河休闲旅游度假景区
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?