Ionic React Without Typescript

Hello people. I am excited to start using Ionic with React, but I came across a question. I’m not used to programming using Typescript, but I noticed that all projects generated using ionic start are generated in TS. I would like to know if there is any alternative or parameter that user can use to have the project created using ES6 or ES7 without Typescript?
Thanks.

Funny, I literally just tried manually converting a project generated by ionic start to not use TypeScript, just out of curiosity. And it seems to work. But I haven’t tried running in Android/iOS yet.

However I’m pretty sure (after running ionic help start and also looking at the starters project) that there isn’t a option in the Ionic CLI, and that TypeScript is the only officially supported setup.

So my recommendation would be to stick with TypeScript, unless you’re just experimenting like me.

After all TypeScript is a superset of JavaScript and supports optional type checking. If you set "strict": false in tsconfig.json that’ll disable mandatory checks, and at that point you can basically write regular JavaScript code, even if the file extension is .ts or .tsx.

Then you can learn more TypeScript features over time if you feel like. Quite a few people are reluctant at first but then end up liking TypeScript.

Funny, I literally just tried manually converting a project generated by ionic start to not use TypeScript, just out of curiosity. And it seems to work. But I haven’t tried running in Android/iOS yet.

Well, it works in the browser if you start the dev server with npm start, but not with ionic serve. There’s clearly something in the Ionic CLI that relies on TypeScript. Strange, because ionic serve is really just calling react-scripts underneath.

Just realised there’s an easier option for people who prefer JavaScript: simply rename all *.tsx files to *.js.

(TypeScript will still be used as the compiler, but you can write regular JavaScript code. This works because the project generated by the Ionic CLI has "allowJs": true in tsconfig.json.)

4 Likes

I’m a “try-first oriented” developer and I say this because in practical terms the difference between JS and TS is just you have assign a type to your objects. I have an additional work of create interfaces before create classes and functions, properties and so on but it’s really worth! TS can provide more predictability about you’re developing, easier to debug and maintain. I think it’s more organized also since all object has an interface as type. Following the good practices now I have a good name and interfaces descriptions to help me to read a code.
My suggestion is try TypeScript! It can be a little annoying at beggining but it worth in projects

It works perfectly on Android. Just change all .tsx to js and run react-scripts.cmd build