[Typescript] Step1 & 2 for converting a js app to ts
2022/8/29 6:23:50
本文主要是介绍[Typescript] Step1 & 2 for converting a js app to ts,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
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
这篇关于[Typescript] Step1 & 2 for converting a js app to ts的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-29如何在 Vue2 的 uni-app 项目中使用 npm ?-icode9专业技术文章分享
- 2024-12-29uni-app vue2微信小程序项目在哪里打开终端并使用npm?-icode9专业技术文章分享
- 2024-12-29怎么在 uni-app Vue2 项目中全局引入 Vant Weapp?-icode9专业技术文章分享
- 2024-12-29uni-app vue2微信小程序项目如何在main.js中全局引入vant?-icode9专业技术文章分享
- 2024-12-28Vue入门教程:从零开始搭建第一个Vue项目
- 2024-12-28Vue CLI入门指南:快速搭建Vue项目
- 2024-12-28Vue3基础知识入门教程
- 2024-12-28Vue3公共组件开发与使用入门教程
- 2024-12-28Vue CLI学习:新手入门教程
- 2024-12-28Vue CLI学习:轻松入门与实践指南