Search code examples
javascriptknockout.jstypescriptyeomanyeoman-generator

How to convert a project from javascript to typescript


I have an existing project I have been working on which I uses Yeoman to build a knockoutjs SPA. I was wandering if there's a tool/way to convert the entire project to typescript.


Solution

  • Javascript is Typescript, you could start including javascript sources in your Typescript project as they are.

    But if you want to take advantage of Typescript strict typing you need to either rewrite the code or add definition files.

    Choose definition files for part of code that are isolated, that should not change, or are planned to be removed. It's a bit faster than rewriting.

    Choose to rewrite in proper Typescript the parts of code you want to maintain in the long run. If the JS is properly done, this task is quite easy, but takes some time.

    Unfortunately there is no automated tool to do that. You have to choose the type of each variable yourself.