-4

EDIT

This question does not answer my question. I'm NOT asking what TS is NOR what it's used for. I'm asking specific questions about it. I'd like clarity on some concepts.

I don't believe this is a duplicate. Someone was kind enough to answer with a simple yes/no questions that I had.

I pointed out a specific concept of TS that I had a question about pointing to an example that I am currently using. I specifically would like to know if I needed to add the keyword string somewhere within my example.

Also, besides transpiler stuff, I just asked if pretty much all the steps I would take to deploy an application in TS would be similar to how it would be done with regular JS.

EDIT END

If applicable, I'd just like a simple yes/no to these questions. Any expounding on the answer is up to you. The yes/no answer will help me figure out how to go about writing this app.

For Typescript(TS), if we can agree that one aspect of it is that pretty much all valid Javascript(JS) is also valid TS.

Example:

const [toggle, setToggle] = useState('');

Would this need to be changed in any way to comply with TS convention/rules? I feel like I'd have to define string with that useState somehow.

Also, besides transpiler usage and all the dependencies installed, would this just be the same process as I would use in JS to get to deployment? As in, would I need to worry about anything else that would be unique to TS that could prevent me from deploying like normal?

mflow
  • 1
  • 5

1 Answers1

1

...if we can agree that one aspect of it is that pretty much all valid Javascript(JS) is also valid TS

If I rephrase it to "can I simply change the file extension from .js to .ts and it will always compile under the default settings", the answer is YES.

However, depending on the settings of your tsconfig.json, it may not work. If for example noImplicitAny is set to true, then even something as simple as function f(x) {} will fail; you must specify the type of x.

besides transpiler usage and all the dependencies installed, would this just be the same process as I would use in JS to get to deployment?

The short answer is YES, but that's a big "besides" in your question. A lot of things can go wrong before transpiling, such as choosing the wrong module option, incomplete definition files, type usage that does not reflect the actual use case, etc. But set all those aside, after transpiling you get a normal JavaScript file, so the deployment can't be any different.

Mu-Tsun Tsai
  • 2,348
  • 1
  • 12
  • 25
  • You should probably go through this quickstart down to the first comments after `tsc greeter.ts` and reconsider the first answer: http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html – Randy Casburn Jul 03 '19 at 05:24
  • 1
    @RandyCasburn And you should probably pay more attention to what I'm saying. The option `noImplicitAny` is false by default, but that doesn't mean you cannot turn it on. – Mu-Tsun Tsai Jul 03 '19 at 05:30
  • 1
    anything can be made to "not work", but that is not the premise of TypeScript. I can make Java so it doesn't ever compile with `javac` too. But again, that is not the premise of Java either. The answer to the first question is YES, given a fresh install of typescript and the code provided. – Randy Casburn Jul 03 '19 at 05:33
  • @RandyCasburn I respect your opinion, but you should judge my answer purely on whether I am stating facts. Since I don't have any "given" in my statement, there's nothing technically wrong with it. – Mu-Tsun Tsai Jul 03 '19 at 05:37
  • 1
    @RandyCasburn I perfectly understand that you're trying to emphasize that TypeScript is supposed to be a superset of JavaScript, but that's not my point of emphasis. What I'm trying to emphasize is that there are not-so-uncommon cases where things can go wrong, which I believe is what OP is concerning about. – Mu-Tsun Tsai Jul 03 '19 at 05:57
  • I would restructure the answer to place the short answer first and weave the other concerns with it. IMHO, you emphasize the corner case over the typical. Besides that, you make a valid point. – ChiefTwoPencils Jul 03 '19 at 06:11
  • Fine, I hope now everyone is happy. – Mu-Tsun Tsai Jul 03 '19 at 06:15
  • @Mu-TsunTsai - If I thought your answer was technically incorrect, I would have downvoted it - which I did not do. I'm attempting to improve the quality of your answer by ensuring it is consistent with what the documentation says about the topic so it doesn't confuse others when they come to review this question. Thanks for making the edit - I've upvoted your answer. You also know I've defended your answers in other posts. Appreciate your openmindedness :-) – Randy Casburn Jul 03 '19 at 13:56
  • Appreciate the responses. I understand that I need to research everything and be sure all parts work. Just wanted to see if I was misunderstanding/missing something. – mflow Jul 04 '19 at 02:33