HiveBrain v1.2.0
Get Started
← Back to all entries
gotchatypescriptreactCritical

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?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
typescripttsxareshouldandusedbetweenfilesthedifference

Problem

I am new to react and I am working on a project. I come across both .ts and .tsx extensions. I don't understand where should I use .ts and .tsx. Any help on this is much appreciated. Thank you!

Solution

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.

Context

Stack Overflow Q#56871384, score: 542

Revisions (0)

No revisions yet.