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,929评论 0赞 7
- RN从零开始----JS错误信息列表{ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...Elbert_Z阅读 13,711评论 0赞 2
- RN模拟器报错中文翻译{ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...一粒沙随风飘摇阅读 13,770评论 0赞 3
- Angular2一些报错信息(json){ "Unterminated string literal.": "未终止的字符串文本。", "Identifi...栗子雨阅读 12,422评论 0赞 3
- angular 报错指引"Unterminated string literal.": "未终止的字符串文本。", "Identifier...两个心阅读 12,660评论 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?