当前位置:网站首页>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
边栏推荐
- Today, I met a senior test developer from Tencent and saw the ceiling of the foundation
- Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
- 英国都在试行4天工作制了,为什么BAT还对996上瘾?
- 基于SSM框架实现的房屋租赁管理系统
- DAY ONE
- Experiment 4: installing packages from Gui
- 每年 2000 亿投资进入芯片领域,「中国芯」创投正蓬勃
- Introduction au GPIO
- What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?
- STM32通过串口进入和唤醒停止模式
猜你喜欢

DAY THREE

Newsletter L Huobi ventures is in-depth contact with genesis public chain

matplotlib画柱状图并添加数值到图中

【通信】两层无线 Femtocell 网络上行链路中的最优功率分配附matlab代码

氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!

Introduction au GPIO

What should I do if the USB flash disk data is formatted and how can I recover the formatted USB flash disk data?

MATLIB从excel表中读取数据并画出函数图像

《数字经济全景白皮书》保险数字化篇 重磅发布

DAY TWO
随机推荐
Please help xampp to do sqlilab is a black
为什么完全背包要用顺序遍历?简要解释一下
【精品】pinia 基于插件pinia-plugin-persist的 持久化
matplotlib画柱状图并添加数值到图中
英国都在试行4天工作制了,为什么BAT还对996上瘾?
Wasserstein slim gain with gradient poverty (wsgain-gp) introduction and code implementation -- missing data filling based on generated countermeasure network
(leetcode) sum of two numbers
DAY SIX
MySQL master-slave multi-source replication (3 master and 1 slave) setup and synchronization test
【向量检索研究系列】产品介绍
Experiment 6: installing eve-ng
氢创未来 产业加速 | 2022氢能专精特新创业大赛报名通道开启!
Computer reinstallation system teaching, one click fool operation, 80% of people have learned
Asset security issues or constraints on the development of the encryption industry, risk control + compliance has become the key to breaking the platform
Pinia module division
App general function test cases
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
【系统分析师之路】第七章 复盘系统设计(面向服务开发方法)
DAY ONE
Server SMP, NUMA, MPP system learning notes.