当前位置:网站首页>Use type aliases in typescript
Use type aliases in typescript
2022-07-06 23:57:00 【User 6256742】
In many packaging tools or use cli The type alias will be provided in the created project , for example Vue-cli Use in @ Can represent absolute path src.
But in use TypeScript Development Node.js There is no such choice in the project , Of course we can be in tsconfig.json Set in path Parameters , But this is only the path without error and is conducive to path prompt , stay ts-node The runtime will still report an error , There is a community called typescript-paths Plug-in to solve the problem , But this plug-in is very unfriendly to incremental compilation (ts After the project is large, you need to compile it in full and change it a little 2 minute ), For this, we can use plug-ins module-alias To solve .
1. First of all, we are still tsconfig.json Set in ts Path alias of , It is possible to ts No error and good path prompt .
"paths": {
"@/*": ["src/*"]
},
Copy
JSON
2. Installing a plug-in module-alias, This is very simple yarn add module-alias perhaps npm intall module-alias
3. Configure the path alias at the top of the entry file ( Can be in package.json But for incremental compilation, you need to copy an additional file )
// variable aliasing
import moduleAlias from "module-alias";
moduleAlias.addAlias("@", __dirname);
Copy
TypeScript
The whole configuration can be configured with multiple aliases , At the same time, you can write callback functions . If you use TS Project development can be combined with TS+Node.js Do incremental compilation This article combines project configuration
边栏推荐
- DAY FOUR
- 设计一个抢红包系统
- 亚朵三顾 IPO
- DAY ONE
- Scholar doctor hahaha
- 使用yum来安装PostgreSQL13.3数据库
- Computer reinstallation system teaching, one click fool operation, 80% of people have learned
- Wasserstein Slim GAIN with Gradient Penalty(WSGAIN-GP)介绍及代码实现——基于生成对抗网络的缺失数据填补
- Oracle中使用包FY_Recover_Data.pck来恢复truncate误操作的表
- 谁说新消费品牌大溃败?背后有人赢麻了
猜你喜欢
App general function test cases
Introduction au GPIO
Experiment 4: installing packages from Gui
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
量子时代计算机怎么保证数据安全?美国公布四项备选加密算法
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
DAY FOUR
【自动化测试框架】关于unittest你需要知道的事
Hydrogen future industry accelerates | the registration channel of 2022 hydrogen energy specialty special new entrepreneurship competition is opened!
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
随机推荐
The tutorial of computer reinstallation win10 system is simple and easy to understand. It can be reinstalled directly without U disk
内网穿透zerotier 外网(手机、电脑等)访问内网设备(树莓派、NAS、电脑等)
服务器SMP、NUMA、MPP体系学习笔记。
基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
微信小程序uploadfile服务器,微信小程序之wx.uploadFile[通俗易懂]
DAY SIX
Introduction au GPIO
Use source code compilation to install postgresql13.3 database
Can online reload system software be used safely? Test use experience to share with you
I've been laid off, and I'll lose money for everything. The days when I once made a monthly salary of 20000 are not coming back
DAY FOUR
【212】php发送post请求有哪三种方法
DevOps可以帮助减少技术债务的十种方式
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
Cas d'essai fonctionnel universel de l'application
DAY TWO
Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work
Do you still have to rely on Simba to shout for a new business that is Kwai?
GPIO简介
okcc呼叫中心的订单管理时怎么样的