ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[Typescript] Step1 & 2 for converting a js app to ts

2022-08-29 01:30:18  阅读:203  来源: 互联网

标签:rename src tests Typescript app ts js jsx files


1. Compiling in "loose mode"

  • Start with all tests passing
  • Rename all .js to .ts, allowing implicit any
  • Fix only things that are not type-checking, or causing compile errors
  • Be careful to avoid changing behavior of function
  • Get test passing again.
# rename all JSX files in src/ to TSX
find src -name '*.jsx' -exec bash -c 'git mv "$0" "${0%.jsx}.tsx"' "{}" \;
# rename all JS files in src/ to TS
find src -name '*.js' -exec bash -c 'git mv "$0" "${0%.js}.ts"' "{}" \;
# rename all JSX files in src/ to TSX
find tests -name '*.jsx' -exec bash -c 'git mv "$0" "${0%.jsx}.tsx"' "{}" \;
# rename all JSX files in src/ to TSX
find tests -name '*.jsx.snap' -exec bash -c 'git mv "$0" "${0%.jsx.snap}.tsx.snap"' "{}" \;
# rename all JS files in tests/ to TS
find tests -name '*.js' -exec bash -c 'git mv "$0" "${0%.js}.ts"' "{}" \;
and don't forget to make this small change to index.html
```diff
--- a/index.html
+++ b/index.html
@@ -8,6 +8,6 @@
   </head>
   <body class="font-sans antialiased h-screen">
     <div id="appContainer" class="w-full h-full"></div>
-    <script src="src/index.js" type="text/javascript"></script>
+    <script src="src/index.ts" type="text/javascript"></script>
   </body>
 </html>
```
and this change to tsconfig for step 1.

2. Explicit Any

  • Start with tests passing
  • Ban implicit any

"noImplicityAny": true,

  • Where possible, provide a specific and appropriate type
    • Import types for dependencies from DefinitelyTypes
    • otherwise explicit any
  • Get tests passing again

 

标签:rename,src,tests,Typescript,app,ts,js,jsx,files
来源: https://www.cnblogs.com/Answer1215/p/16634618.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有