当前位置:网站首页>TypeScript在使用中出现的问题记录
TypeScript在使用中出现的问题记录
2022-07-31 00:38:00 【百里狂生】
TypeScript
元组声明BUG
let list: [string, number] = ['hello', 123];
list.push('world'); // success
// 理论上是不可以给 list 添加任何元素的
setter, getter 编译需要支持 es5
# 编译成js文件便于执行
$ tsc app.ts
app.js
# 使用es5 的方式编译成js文件便于执行
$ tsc -t es5 app.ts
app.js
# 使用 node 执行js文件
$ node app.js
TypeScript 在 import 文件的时候提示文件不存在
// src/main.ts
import popup from './comoonents/popup/popup';
popup({
})
然后启动 npm run serve
报错,./components/popup/popup
文件不存在。
原因是需要在 webpack.config.js 中添加一行配置:
moduel.exports = {
mode: 'development',
entry: './src/main.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'main.js'
},
devServer: {
},
resolve: {
// 需要调整 import 文件的查找顺序,这样才能让 webapck 打包的时候找到 .ts 文件的模块
extensions: ['.ts', '.js', '.json']
},
module: {
rules: [
{
test: /\.ts$/,
use: ['ts-loader'],
// 屏蔽 node_modules 中的 .ts 文件
exclude: /node_modules/
}
]
}
}
边栏推荐
- 如何在WordPress网站上添加导航菜单
- Meeting OA project pending meeting, all meeting functions
- Encapsulate and obtain system user information, roles and permission control
- 从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术
- xss绕过:prompt(1)
- Jetpack Compose learning (8) - State and remeber
- MySQL筑基篇之增删改查
- Shell编程之条件语句
- How to solve the error of joiplay simulator
- MySQL系列一:账号管理与引擎
猜你喜欢
(五)fastai应用
Shell编程之条件语句
MySQL数据库面试题总结(2022最新版)
作业:iptables防止nmap扫描以及binlog
h264和h265解码上的区别
DNS resolution process [visit website]
Preparations for web vulnerabilities
What is Promise?What is the principle of Promise?How to use Promises?
【唐宇迪 深度学习-3D点云实战系列】学习笔记
[In-depth and easy-to-follow FPGA learning 15---------- Timing analysis basics]
随机推荐
Method for deduplication of object collection
Regular expression password policy and regular backtracking mechanism bypass
Mysql systemized JOIN operation example analysis
C language force buckles the rotating image of the 48th question.auxiliary array
Preparations for web vulnerabilities
[Yugong Series] July 2022 Go Teaching Course 016-Logical Operators and Other Operators of Operators
从笔试包装类型的11个常见判断是否相等的例子理解:包装类型、自动装箱与拆箱的原理、装箱拆箱的发生时机、包装类型的常量池技术
How to Repair Word File Corruption
Detailed explanation of 9 common reasons for MySQL index failure
MySQL triggers
.NET Cross-Platform Application Development Hands-on Tutorial | Build a Kanban-style Todo App with Uno Platform
ABC 261 F - Sorting Color Balls(逆序对)
pytorch双线性插值
PHP图片添加文字水印
redis学习
Kotlin协程:协程上下文与上下文元素
Linux 部署mysql 5.7全程跟踪 完整步骤 django部署
限制字符绕过
xss的绕过
The difference between truncate and delete in MySQL database