首页 > 其他分享 >[Typescript] Step1 & 2 for converting a js app to ts

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

时间:2022-08-29 01:33:22浏览次数:51  
标签: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
From: https://www.cnblogs.com/Answer1215/p/16634618.html

相关文章

  • Bootstrap基础介绍一
    前端框架Bootstrap该框架已经帮你写好了很多页面样式,你如果需要使用,只需要下载它对应文件,之后直接cv拷贝即可在使用Bootstrap的时候所有的页面样式都只需要你通过class来......
  • appium 移动端自动化测试工具
    appium移动端自动化测试工具appium移动端自动化测试工具appium是哟个自动化测试开源工具支持ios和安卓平台的应用以及web应用和混合应用appium是一个跨平台的工......
  • Linux Kernel in a Nutshell - 7
    CustomizingaKernel原文链接我的博客以·问题·做关键字搜索,还有问题构建你自己的Linux内核版本最困难的部分,应该就是确定哪一个驱动以及配置选项是你的设备需要的......
  • Linux Kernel in a Nutshell - 8
    KernelConfigurationRecipes原文链接我的博客前面介绍了重新配置内核的机制,本章介绍制作自己的内核通常会遇到的那些问题,并给出对应指令来处理它。DisksLinux内核......
  • randomize( ) with Arguments
    当调用不带参数的randomize()方法时,它会为对象中的所有随机变量(声明为rand或randc)分配新值,满足所有约束。当使用参数调用randomize()时,这些参数指定该对象内的随机......
  • CF76E Points
    可以把题目转换成求:\[\sum_{i=1}^{n}\sum_{j=i+1}^{n}[(x_i-x_j)^2+(y_i-y_j)^2]\]继续化简:\[=\sum_{i=1}^{n}\sum_{j=i+1}^{n}(x_i-x_j)^2......
  • 「postOI」Cross Swapping
    题意给出一个\(n\timesn\)的矩阵\(A\),你可以进行下述操作任意多次:指定整数\(k\)(\(1\lek\len\)),使\(A_{ni}\)与\(A_{in}\)交换。求你能得到的字典序最小的矩阵......
  • Apache HTTP Server 修改最大连接数maxclients
    ApacheHTTPServer修改最大连接数maxclients--ITeye博客 https://www.iteye.com/blog/awenhaowenchao-1735968 在公司内网用到了apache2做web服务器,每当内部发文......
  • gym-103708D Different Pass a Ports
    DifferentPassaPorts矩阵快速幂模板图的邻接矩阵的\(k\)次幂就是从图上所有点走\(k\)步的方案数#include<iostream>#include<cstdio>usingnamespacestd;......
  • rh358 002 fact变量获取 ansible配置网络 service_facts
    通过ansible获取网络信息1.如何获取fact事实变量方式1:ansibleservera-mservera方式2:剧本[root@workstationansible]#catake.yaml----name:getallfac......